Codeforces 670D2 Magic Powder
来源:互联网 发布:手机指纹解锁软件 编辑:程序博客网 时间:2024/05/16 14:35
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 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.
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种材料,以及M个魔法材料。
每个魔法材料可以变成任意一种魔法材料。
现在已知做一个饼干要用每种材料Ai个,而且已知每种饼干我们初始有Bi个。
问最多可以做出来多少饼干。
思路:
明显如果我们能够做出来x个饼干,那么一定能够做出来x-1个饼干,同理x-2也一定能够做出来。
所以这里一定有一个单调性在这里边。
那么我们二分结果,然后check一下就行。
注意数据范围。
Ac代码:
#include<stdio.h>#include<string.h>using namespace std;#define ll __int64ll n,m;ll a[150000];ll b[150000];ll Slove(ll mid){ ll sum=0; for(ll i=0;i<n;i++) { if(b[i]-a[i]*mid<0)sum+=b[i]-a[i]*mid; if(-sum>m)return 0; } if(sum>=0)return 1; if(sum<0&&-sum<=m)return 1; return 0;}int main(){ while(~scanf("%I64d%I64d",&n,&m)) { for(ll i=0;i<n;i++)scanf("%I64d",&a[i]); for(ll i=0;i<n;i++)scanf("%I64d",&b[i]); ll ans=0; ll l=0; ll r=2000000000; while(r-l>=0) { ll mid=(l+r)/2; if(Slove(mid)==1) { l=mid+1; ans=mid; } else r=mid-1; } printf("%I64d\n",ans); }}
- Codeforces 670D2 Magic Powder
- 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(二分)
- coderforces 670D2 Magic Powder - 2
- codeforce 670D2 Magic Powder - 2
- D2. Magic Powder - 2
- Codeforces Round #350 (Div. 2) D2. Magic Powder - 2 670D 【二分答案】
- Codeforces Round #350 (Div. 2) D2 - Magic Powder - 2
- Codeforces Round #350 (Div. 2) D2 Magic Powder - 2【二分】
- Vim编辑器相关
- 基于redis的分布式锁的实现
- Discuz!论坛教程之设置帖子被访问后自动提升主题
- Hibernate4调用SQL和存储过程
- C++多线程
- Codeforces 670D2 Magic Powder
- Log4Net使用详解
- js数组与对象的区别
- 389. Find the Difference
- Vuex,从入门到放弃
- jdk环境配置
- Visual Studio Code 1.11 发布
- IntelliJ IDEA使用Maven创建Java Web项目
- .net aspx ashx sharepoint 输出图片IE不显示