CodeForces 670D2 Magic Powder - 2
2016-05-07 11:39
435 查看
E - Magic Powder - 2
Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d
& %I64u
Submit Status Practice CodeForces
670D2
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 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.
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
Input
Output
Input
Output
Input
Output
Input
Output
FAQ | About Virtual Judge | Forum | Discuss | Open
Source Project
题意:有n中材料,每种材料有b克,他想做饼干,做1个饼干需要每种材料ai克,现在有k克魔法粉,这k克魔法粉可以变成任意一种材料,求最终最多做多少个饼干;
另一个所有数据范围变成10^9时我们可以想到,他最多做不超过2*(10^9)个饼干,所以我们可以二分搜索答案,一直到找到符合题意de饼干个数为止;
注意中间过程会爆int的所以用long long
Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d
& %I64u
Submit Status Practice CodeForces
670D2
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 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.
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
Input
1 1000000000 1 1000000000
Output
2000000000
Input
10 1 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1 1 1 1 1 1 1 1 1 1
Output
0
Input
3 1 2 1 4 11 3 16
Output
4
Input
4 34 3 5 6
11 12 14 20
Output
3
FAQ | About Virtual Judge | Forum | Discuss | Open
Source Project
题意:有n中材料,每种材料有b克,他想做饼干,做1个饼干需要每种材料ai克,现在有k克魔法粉,这k克魔法粉可以变成任意一种材料,求最终最多做多少个饼干;
另一个所有数据范围变成10^9时我们可以想到,他最多做不超过2*(10^9)个饼干,所以我们可以二分搜索答案,一直到找到符合题意de饼干个数为止;
注意中间过程会爆int的所以用long long
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<queue>
#include<cctype>
#include <map>
#define max(a,b)(a>b?a:b)
#define min(a,b)(a<b?a:b)
#define INF 0x3f3f3f3f
typedef long long ll;
using namespace std;
#define N 110000int n;
ll k,Max;
ll a[N],b[N];
ll Search(ll l,ll r)
{
while(l<=r)
{
ll mid=(l+r)/2;
ll sum=0;
for(int i=1;i<=n;i++)
{
if(b[i]<a[i]*mid)
sum=sum+(a[i]*mid)-b[i];
if(sum>k)
break;
}
if(sum==k)
return mid;
else if(sum<k)
l=mid+1;
else
r=mid-1;
}
return l-1;
}
int main()
{
while(scanf("%d%I64d",&n,&k)!=EOF)
{
for(int i=1;i<=n;i++)
scanf("%I64d",&a[i]);
for(int i=1;i<=n;i++)
scanf("%I64d",&b[i]);
Max=2*1e9+10;
ll ans=Search(0,Max);
printf("%I64d\n",ans);
}
return 0;
}
相关文章推荐
- 动态获得类的属性来构建模型
- 3.26日第六次作业,第10章质量,11章人力
- 未将对象引用设置到对象的实例
- Python数据分析示例(2)Day3
- 回调函数之类相关
- 【Android】通用系列 —— 用简单通用的方式操作ListView
- Xamarin开发Android---提示、跳转、传递数值
- SpringMvc学习与使用
- centos7开放端口
- Apache与Tomcat的关系和区别
- RPC, REST 与 SOCKET
- 八大排序算法 之 快速排序(填坑法)
- TortoiseGit 使用教程
- 关于Java中Scanner对象的hasNext()方法对实现Readable接口的对象中的read()方法调用的探讨
- HDU 5159 Card (概率DP)
- STM32位带操作----待更
- 【Ubuntu】搭建LAMP服务器Apache+MySQL+PHP
- 选择恐惧症的福音!教你认清MVC,MVP和MVVM
- 数值最优化:理解L-BFGS
- 欢迎使用CSDN-markdown编辑器