codeforce Round #379 (Div. 2)C(贪心)

来源:互联网 发布:深圳网络固定地址 编辑:程序博客网 时间:2024/05/22 09:39

题目链接

C. Anton and Making Potions
贪心,用魔法肯定比不要要好,所以遍历bi对每一个bid中找到对应的sb[i]d[p]p的最大值,
复杂度O(mlg(k))
不过要注意的是数据有点大,还有就是注意边值数据,对于边值数据最好是在数组中设置哨兵。

代码

#include <cstdio>#include <cstring>#include <queue>#include<algorithm>#include<iostream>#include<cmath>#include<vector>#define INF 0x3f3f3f3f#define maxn 200009#define fi first#define se secondusing namespace std;typedef long long LL;typedef unsigned long long uLL;typedef pair<int,int> PI;LL n,m,k,x,s;LL ans;LL a[maxn],b[maxn],c[maxn],d[maxn];int main(){        //freopen("H:\\c++\\file\\stdin.txt","r",stdin);        cin>>n>>m>>k>>x>>s;        memset(a,0,sizeof(a));        memset(b,0,sizeof(b));        memset(c,0,sizeof(c));        memset(d,0,sizeof(d));        a[0] = x;        d[k+1] = (LL)3*1e9;        for(int i=1 ; i<=m ; ++i)cin>>a[i];        for(int i=1; i<=m ; ++i)cin>>b[i];        for(int i=1 ; i<=k ; ++i)cin>>c[i];        for(int i=1 ; i<=k ; ++i)cin>>d[i];        ans = n*x;        for(int i=0 ; i<=m ; ++i)        {            if(b[i]>s)continue;            int p = upper_bound(d,d+k+1,s-b[i])-d;            while(p>=0 && d[p]>s-b[i])p--;             LL re = n-c[p];            if(re<0)ans  =0;            ans = min(ans,re*a[i]);        }        cout<<ans<<endl;       return 0;}
0 0