CodeForces
来源:互联网 发布:世宗大王级驱逐舰知乎 编辑:程序博客网 时间:2024/05/20 22:01
点击打开题目链接
The term of this problem is the same as the previous one, the only exception — increased restrictions.
The first line contains two positive integers n and k (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 the i-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 the i-th ingredient, which Apollinaria has.
Print the maximum number of cookies, which Apollinaria will be able to bake using the ingredients that she has and the magic powder.
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
题目大意:
有n种原料和k课魔法粉末,第二行为做一个饼干需要的每种原料数,第三行为每种原料总共有多少克。魔法粉末可以任意加到原料上,求最多可以做多少饼干。做的二分题还是少,当时没想到二分饼干数,一直超时样例。
思路:
二分饼干数求解。
附上AC代码:
#include<iostream>#include<algorithm>using namespace std;typedef long long ll;const int maxn=100000+5;ll n,k;ll maxd;ll sum;struct nodes{ ll need,have;}node[maxn];int main(){ ios::sync_with_stdio(false); while(cin>>n>>k){ sum=0; for(int i=1;i<=n;i++) cin>>node[i].need; for(int i=1;i<=n;i++){ cin>>node[i].have; maxd=max((node[i].have+k)/node[i].need,maxd); } ll l=0,r=maxd; while(l<=r){ ll mid=(l+r)/2; ll tmp=k; ll ans=0; for(int i=1;i<=n;i++){ if(tmp<0){ ans=1; break; } if(node[i].have/node[i].need>=mid)continue; else if(node[i].have/node[i].need<mid){ tmp-=mid*node[i].need-node[i].have; if(tmp<0){ ans=1; break; } } } if(ans==1){//tmp<0,魔法粉末不够用 r=mid-1; } else if(ans==0){ sum=max(sum,mid); l=mid+1; } } cout<<sum<<endl; } return 0;}
- codeforces~~~
- Codeforces
- codeforces
- Codeforces
- codeforces
- codeforces
- Codeforces
- Codeforces
- CodeForces
- CodeForces
- CodeForces
- CodeForces
- CodeForces
- Codeforces
- Codeforces
- Codeforces
- Codeforces
- Codeforces
- 爬取代理ip
- 新建jsp报错“The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path”
- CTF实验吧-登陆一下好吗??【false SQL注入】
- 2017 年中总结
- Vue-组件化应用构建
- CodeForces
- linux系统top命令分析CPU和内存详解
- linux 用户空间与内核空间——高端内存详解
- c#程序打包成可执行文件
- mysql函数+定时器
- 44-扑克牌的顺序
- java线上服务问题排查
- 接口面试
- js函数执行先后顺序