CodeForces - 670D2 Magic Powder - 2 (二分&模拟)
来源:互联网 发布:淘宝网1元秒杀在哪里找 编辑:程序博客网 时间:2024/05/16 11:59
Description
The term of this problem is the same as the previous one, the only exception — increased restrictions.
Input
The first line contains two positive integers n andk (1 ≤ n ≤ 100 000, 1 ≤ k ≤ 109) — the number of ingredients and the number of grams of the magic powder.
The second line contains the sequence a1, a2, ..., an (1 ≤ ai ≤ 109), where the i-th number is equal to the number of grams of thei-th ingredient, needed to bake one cookie.
The third line contains the sequence b1, b2, ..., bn (1 ≤ bi ≤ 109), where the i-th number is equal to the number of grams of thei-th ingredient, which Apollinaria has.
Output
Print the maximum number of cookies, which Apollinaria will be able to bake using the ingredients that she has and the magic powder.
Sample Input
1 100000000011000000000
2000000000
10 11000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 10000000001 1 1 1 1 1 1 1 1 1
0
3 12 1 411 3 16
4
4 34 3 5 611 12 14 20
3
Sample Output
Hint
Source
#include<stdio.h>#include<string.h>#include<algorithm>#include<iostream>#define ll long long#define INF 0x3f3f3f3f#define N 100010using namespace std;ll a[N],b[N];int n;ll k;bool judge(ll x){ll s=k;for(int i=1;i<=n;i++){if(x*a[i]>=b[i])s-=(x*a[i]-b[i]);if(s<0)return false;}return true;}int main(){int i;while(scanf("%d%lld",&n,&k)!=EOF){for(i=1;i<=n;i++)scanf("%lld",&a[i]);for(i=1;i<=n;i++)scanf("%lld",&b[i]);if(n==1){printf("%lld\n",(k+b[1])/a[1]);continue;}ll l=0,r=3000000000ll,mid,ans;while(l<=r){mid=(l+r)>>1ll;if(judge(mid)){l=mid+1;ans=mid;}elser=mid-1;}printf("%lld\n",ans);}return 0;}
#include<stdio.h>#include<string.h>#include<algorithm>#include<iostream>#define ll long long#define INF 0x3f3f3f3f#define N 100010using namespace std;ll a[N],b[N];struct zz{ll a;ll b;ll c;ll d;}p[N];bool cmp(zz a,zz b){return a.a<b.a;}int n;ll k;bool judge(ll x){ll s=0;for(int i=1;i<=n;i++){if(p[i].a<x)s+=p[i].c+(x-p[i].a-1)*p[i].d;if(s>k)return false;}return true;}int main(){int i;while(scanf("%d%lld",&n,&k)!=EOF){for(i=1;i<=n;i++){scanf("%lld",&a[i]);p[i].d=a[i];}for(i=1;i<=n;i++)scanf("%lld",&b[i]);if(n==1){printf("%lld\n",(k+b[1])/a[1]);continue;}for(i=1;i<=n;i++){p[i].a=b[i]/a[i];p[i].b=b[i]%a[i];p[i].c=a[i]-p[i].b;}sort(p+1,p+n+1,cmp);ll l=0,r=3000000000ll,mid,ans;while(l<=r){mid=(l+r)>>1ll;if(judge(mid)){l=mid+1;ans=mid;}elser=mid-1;}printf("%lld\n",ans);}return 0;}
- CodeForces - 670D2 Magic Powder - 2 (二分&模拟)
- CodeForces 670D2 Magic Powder - 2(二分+贪心)
- 【CodeForces】670D2 - Magic Powder - 2(二分)
- Codeforces 670D2:Magic Powder - 2(二分)
- Codeforces 670D2 Magic Powder - 2 二分答案
- codeforces 670D2. Magic Powder - 2
- codeforces 670D2 - Magic Powder - 2
- CodeForces 670D2 Magic Powder - 2
- 【CodeForces】[670D2]Magic Powder - 2
- CodeForces 670D2 Magic Powder - 2
- Codeforces 670D2 Magic Powder-2
- Codeforces 670D2 Magic Powder
- Codeforces Round #350 (Div. 2) D2 Magic Powder - 2【二分】
- Codeforces Round #350 (Div. 2) D2. Magic Powder - 2 【二分】
- Codeforces Round #350 (Div. 2) D2. Magic Powder - 2 670D 【二分答案】
- cf 670D2 Magic Powder - 2 二分裸题
- D2. Magic Powder - 2
- CodeForces 670D Magic Powder - 2 (二分)
- 必须掌握的八种排序(1-2)--插入排序,希尔排序
- mongoVUE:未将对象引用设置到对象的实例
- 代码创建plist文件
- java MAP
- iOS面试经验
- CodeForces - 670D2 Magic Powder - 2 (二分&模拟)
- 对kvm虚拟机恢复有用知识
- 练习三1006
- 不安装oracle客户端,用plsql连接oracle
- 关于NSRunLoop和NSTimer的深入理解
- CSS 元素垂直居中的 6种方法
- SimpleAdapter使用案例
- [caffe]thread
- ip default-network 用法举例(使用静态默认路由实现网络互连)