Codeforces Round #350 (Div. 2)_D2 - Magic Powder - 2
1 second
256 megabytes
standard input
standard output
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 1000000000
1
1000000000
2000000000
10 1
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000
1 1 1 1 1 1 1 1 1 1
0
3 1
2 1 4
11 3 16
4
4 3
4 3 5 6
11 12 14 20
3
题解:二分答案的经典应用
#include<cstdio>
#define LL long long
#define FFC(i,a,b) for(int i=a;i<=b;i++)
LL a[],b[],n,k,maxn=*1e9+;
void fre(){freopen("c:\\acm\\input.txt","r",stdin);}
LL search(LL l,LL r){
LL mid,sum;
while(l<=r){
mid=(l+r)>>,sum=;
FFC(i,,n){
sum+=a[i]*mid-b[i]>?a[i]*mid-b[i]:;
if(sum>k)break;//防爆LL
}
if(sum==k)return mid;
else if(sum<k)l=mid+;
else r=mid-;
}
return r;
}
int main(){
//fre();
while(~scanf("%I64d%I64d",&n,&k)){
FFC(i,,n)scanf("%I64d",&a[i]);
FFC(i,,n)scanf("%I64d",&b[i]);
printf("%I64d\n",search(,maxn));
}
return ;
}
Codeforces Round #350 (Div. 2)_D2 - Magic Powder - 2的更多相关文章
- Codeforces Round #350 (Div. 2) D1. Magic Powder - 1 二分
D1. Magic Powder - 1 题目连接: http://www.codeforces.com/contest/670/problem/D1 Description This problem ...
- Codeforces Round #350 (Div. 2) D2. Magic Powder - 2
题目链接: http://codeforces.com/contest/670/problem/D2 题解: 二分答案. #include<iostream> #include<cs ...
- Codeforces Round #350 (Div. 2)A,B,C,D1
A. Holidays time limit per test 1 second memory limit per test 256 megabytes input standard input ou ...
- Codeforces Round #350 (Div. 2) D1
D1. Magic Powder - 1 time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces Round #350 (Div. 2) A B C D1 D2 水题【D2 【二分+枚举】好题】
A. Holidays 题意:一个星球 五天工作,两天休息.给你一个1e6的数字n,问你最少和最多休息几天.思路:我居然写成模拟题QAQ. #include<bits/stdc++.h> ...
- Codeforces Round #335 (Div. 2) A. Magic Spheres 水题
A. Magic Spheres Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.codeforces.com/contest/606/ ...
- Codeforces Round #443 (Div. 1) D. Magic Breeding 位运算
D. Magic Breeding link http://codeforces.com/contest/878/problem/D description Nikita and Sasha play ...
- Codeforces Round #350 (Div. 2) E. Correct Bracket Sequence Editor 模拟
题目链接: http://codeforces.com/contest/670/problem/E 题解: 用STL的list和stack模拟的,没想到跑的还挺快. 代码: #include<i ...
- Codeforces Round #335 (Div. 2) A. Magic Spheres 模拟
A. Magic Spheres Carl is a beginner magician. He has a blue, b violet and c orange magic spheres. ...
随机推荐
- sf中schedule设定
博客园龄有两年多了,看了一下我发的文章数和最后发布的日期,不禁的心头一怔,已经有一年都没有写更新博客了.突然想起一个句子好像说的是我:间歇性踌躇满志,持续性懒惰等死.最近也看到一位好朋友的qq个性签名 ...
- matlab imshow()函数显示白色图像问题
在MATLAB中,我们常使用imshow()函数来显示图像,而此时的图像矩阵可能经过了某种运算.在MATLAB中,为了保证精度,经过了运算的图像矩阵I其数据类型会从uint8型变成double型.如果 ...
- oracle 字段类型详解
CHAR 固定长度字符串 最大长度2000 bytes VARCHAR2 可变长度的字符串 最大长度4000 bytes 可做索引的最大长度749 NCHAR 根据字符集而定的固定长度字符串 最大长度 ...
- node读写json文件(进阶)
该方法可用于修改配置文件,直接上代码 fs.readFile('test1.json','utf8',function (err, data) { if(err) console.log(err); ...
- js-轮播图
<!DOCTYPE HTML> <html> <head> <meta http-equiv="content-type" charset ...
- Java Swing 日期控件(转载)
http://www.cnblogs.com/lzy1991/p/5714935.html
- Modernizr 测试浏览器是否兼容相应属性
Modernizr 测试浏览器是否兼容相应属性
- React 相关资料
learncodeacademy/react-js-tutorials MobX
- CentOS正确关机方法
1关机前准备 1.1观察系统使用状态 · 谁在线:who · 联网状态:netstat -a · 后台执行的程序:ps -aux 1.2通知在线使用者关 ...
- 一步一步学EF系列【6、IOC 之AutoFac】
前言 之前的前5篇作为EF方面的基础篇,后面我们将使用MVC+EF 并且使用IOC ,Repository,UnitOfWork,DbContext来整体来学习.因为后面要用到IOC,所以本篇先单独先 ...