codeforces 670D2. Magic Powder - 2
2016-05-06 10:57
417 查看
D2. Magic Powder - 2
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
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.
Examples
Input
Output
Input
Output
Input
Output
Input
Output
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
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.
Examples
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
题意:
制作一块饼干需要n种原料,每一种ai克。现在有每种原料分别bi克。而且你现在还有k克的魔法粉末,每一克粉末都可以当作任意一种原料一克使用。球最多能制作多少个饼干
思路:
直接二分饼干数+贪心即可
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
const int inf = 2147483647;
const double PI = acos(-1.0);
const double e = 2.718281828459;
const int mod = 1000000007;
typedef long long LL;
#pragma comment(linker, "/STACK:102400000,102400000")
//freopen("in.txt","r",stdin); //输入重定向,输入数据将从in.txt文件中读取
//freopen("out.txt","w",stdout); //输出重定向,输出数据将保存在out.txt文件中cin
struct node
{
LL a, b;
}x[100005];
int main()
{
LL n, k;
int i, j;
while (cin >> n >> k)
{
for (i = 1; i <= n; ++i)
{
scanf("%lld", &x[i].a);
}
LL m = 0;
for (i = 1; i <= n; ++i)
{
scanf("%lld", &x[i].b);
m = max((x[i].b + k) / x[i].a, m);
}
LL L = 0, R = m;
LL mmax = 0;
//cout << L << R << endl;
while (L <= R)
{
LL mid = (L + R) / 2;
LL p = k;
LL ans = 0;
for (i = 1; i <= n; ++i)
{
if (p < 0)
{
ans = 1;
break;
}
if (x[i].b / x[i].a >= mid)
continue;
else
{
p -= mid * x[i].a - x[i].b;
}
if (p < 0)
{
ans = 1;
break;
}
}
if (ans)
{
R = mid - 1;
}
else
{
mmax = max(mmax, mid);
L = mid + 1;
}
//cout << mid <<" "<<mmax << endl;
}
printf("%lld\n", mmax);
}
}
/*
3 2
2 1 411 3 16
*/
相关文章推荐
- Bootstrap + Font Awesome
- 代理模式(一)
- C++ 第四次实验 作业
- ELK安装配置
- 资本过冬天 企业文件云存储却逆袭升温(亿方云获得了500万美元的投资)
- 转: javaWeb学习总结(见过最好的知识合集,相当给力,强烈推荐)
- [团队项目]Scrum 项目1.0 (演说视频)
- Scrum项目1.0
- fzu---Problem 2232 炉石传说(二分匹配)
- win7 VS2012+openCV-2.4.11 配置
- HDU 4389 X mod f(x) 数位dp
- squid实现反向代理!!!
- c++中的智能指针auto_ptr解析
- 队列和栈的函数
- iOS网络开发基础--发送HTTP请求
- CrashHandler在开发中运用(单例模式)
- python3 字符编码问题原理简介
- image stitch(国外开源的图像拼接)
- CentOS7中关闭selinux
- oracle“记录被另一个用户锁住”