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. ftp服务器端的安装及配置

    搭建过程 安装 vsftp 服务(yum 安装即可) 配置/etc/vsftpd/vsftpd.conf   anonymous_enable=NO #禁止匿名登录 local_enable=YES ...

  2. vs2008编译FileZilla服务端源码

    vs2008编译FileZilla服务端源码 FileZilla服务端下载地址:https://download.filezilla-project.org/server/.FileZilla服务端源 ...

  3. js 循环迭代定时器的执行次数和执行顺序??主要是因为js是单线程

    当定时器运行时即使每个迭代中执行的是setTimeout(.., 0),所有的回调函数依然是在循环结束后才会被执行 for语句开始赋值i=1;settimeout语句1000毫秒后把timer函数加入 ...

  4. java 中文乱码

    1.URL编码 String str = URLEncoder.encode("中文乱码","UTF-8");//编码 String newStr = URLD ...

  5. JS跨域访问问题

    js跨域了. 只能给几个资料参考了:http://blog.csdn.net/lovingprince/article/details/2954675 http://www.kuqin.com/web ...

  6. icon的使用

    在前端页面设计时,不免使用的就是图标,下面就我使用图标icon分享一下经验 1.icon插件,现在比较好的是bootstrap自带的,fontawesome,链接地址:http://fontaweso ...

  7. 设计模式--装饰者设计模式(Decorator)

    装饰者模式又叫包装模式. 通过另一个对象来扩展自己的行为,在不破坏类的封装的情况下,实现松耦合,易扩展的效果.   抽象组件角色: 一个抽象接口,是被装饰类和装饰类的父接口可以给这些对象动态地添加职责 ...

  8. 一般增广路方法求网络最大流(Ford-Fulkerson算法)

    /* Time:2015-6-18 接触网络流好几天了 写的第一个模版————Ford-Fulkerson算法 作用:求解网络最大流 注意:源点是0 汇点是1 如果题目输入的是1到n 请预处理减1 * ...

  9. Maven使用笔记

    Maven是一个项目管理工具,它包含了一个项目对象模型 (Project Object Model), 一组标准插件(生命周期各阶段是绑定插件中的目标来完成项目构建工作) 一个项目生命周期(Proje ...

  10. INSTALL_FAILED_NO_MATCHING_ABIS

    在运行写好的cocos的demo时候,安装出现以下问题: 后来发现是因为自己用cygwin生成的x86的.so文件跟自己的魅族3机器CPU不适配!!! 参考:http://stackoverflow. ...