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
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 3
4 3 5 6
11 12 14 20
output
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的更多相关文章

  1. Codeforces Round #350 (Div. 2) D1. Magic Powder - 1 二分

    D1. Magic Powder - 1 题目连接: http://www.codeforces.com/contest/670/problem/D1 Description This problem ...

  2. Codeforces Round #350 (Div. 2) D2. Magic Powder - 2

    题目链接: http://codeforces.com/contest/670/problem/D2 题解: 二分答案. #include<iostream> #include<cs ...

  3. 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 ...

  4. Codeforces Round #350 (Div. 2) D1

    D1. Magic Powder - 1 time limit per test 1 second memory limit per test 256 megabytes input standard ...

  5. Codeforces Round #350 (Div. 2) A B C D1 D2 水题【D2 【二分+枚举】好题】

    A. Holidays 题意:一个星球 五天工作,两天休息.给你一个1e6的数字n,问你最少和最多休息几天.思路:我居然写成模拟题QAQ. #include<bits/stdc++.h> ...

  6. 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/ ...

  7. Codeforces Round #443 (Div. 1) D. Magic Breeding 位运算

    D. Magic Breeding link http://codeforces.com/contest/878/problem/D description Nikita and Sasha play ...

  8. Codeforces Round #350 (Div. 2) E. Correct Bracket Sequence Editor 模拟

    题目链接: http://codeforces.com/contest/670/problem/E 题解: 用STL的list和stack模拟的,没想到跑的还挺快. 代码: #include<i ...

  9. 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. ...

随机推荐

  1. KVM设置DHCP、DNS、Gateway

    添加网卡 sudo vi /etc/network/interfaces #添加下面的配置 >>>>>>>> auto tap0 iface tap0 ...

  2. 关于用PS改变图像颜色

    由于写的一个页面主色调变了,里面的一些图标颜色也要相应改变,自己难得重新去psd里面截图,就想着用ps,看能否直接能变换一下图标颜色.其实方法也很简单的. 1:用ps打开需要改变图标颜色的文件,然后选 ...

  3. java线程condition

    子线程先执行一段代码,再主线程再执行一段代码,两个线程都循环执行50遍.用2个condition来实现,一个是子线程的condition,一个是主线程的condition,代码如下: package ...

  4. js--事件对象的理解5-

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  5. iOS毛玻璃擦除效果

    思路:首先我的思路放两个imageView在Controller里把高清的图片放在下面,带有毛玻璃效果的图片放在上面. //在Controller的view上加一个手势代码如下(温馨提示,开启imae ...

  6. 5.oracle建表的时候同时创建主键,外键,注释,约束,索引

    5.oracle建表的时候同时创建主键,外键,注释,约束,索引 1 --主键 )); ) ,constraint aba_pr primary key(id,name1)); --外键 )); --复 ...

  7. 使用Slua框架开发Unity项目的重要步骤

    下载与安装 下载地址 GitHub 安装过程1.下载最新版,这里, 解压缩,将Assets目录里的所有内容复制到你的工程中,对于最终产品,可以删除slua_src,例子,文档等内容,如果是开发阶段则无 ...

  8. 从零开始学Axure原型设计(高级篇)

    如果你熟悉了Axure的部件库,那么你可以得心应手地画出心目中产品的线框图:如果你会用Axure的母版.动态面板功能,那么你应该能够画出一些简单网站的原型图:但只有你精通了Axure的条件逻辑.变量. ...

  9. git clone 出现 RPC failed 错误的解决方案

    今天使用git clone一个大型项目的时候出现了如下错误:

  10. Vultr VPS测试IP $5/月KVM-512MB/15G SSD/1T

    vultr主要卖点是:SSD硬盘.超低价格.全球13个机房.10Gb服务器带宽.3GHz CPU.性能优异.vultr vps详细评测可参考这篇文章. 以下是vutlr vps官方提供的测试IP地址: ...