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. ...
随机推荐
- CSS:haslayout知多少
我们都知道浏览器有bug,而IE的bug似乎比大多数浏览器都多.IE的表现与其他浏览器不同的原因之一就是,显示引擎使用一个称为布局(layout)的内部概念. 因为布局是专门针对显示引擎内部工作方 ...
- svn的基本配置及安装
1.检查是否已安装 rpm -qa subversion 如果要卸载旧版本: yum remove subversion 2.安装 yum install subversion 3.检查是否安装成功 ...
- webAppRootKey
web.xml中webAppRootKey ------------------------------------------------------------------------------ ...
- easyUI的treegrid列表添加查询
一些数据使用treegrid显示,添加筛选条件, 首先创建treegrid列表 var tree = $("#TreeGrid").treegrid({ url:"cha ...
- 深入分析Java Web开发
Web请求过程 如何发起请求:browser,httpclient http解析:chrome ,cache Dns域名解析:域名缓存 cdn:负载,动态加速,回源 Java I/O I/0类库的基本 ...
- Black Jack
Black Jack 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5602 记忆化搜索 用dp[0][i][j]记录当player为i,banker为 ...
- Node.js:EventEmitter
概要:本篇博客主要介绍EventEmitter Node.js所有的异步I/O操作在完成时都会发送一个事件到事件队列.事件由EventEmitter对象提供.下面通过一个例子来说明EventEmitt ...
- Node.js:服务器与数据流
1.Node 常被用来构建服务器,下面代码就是创建了一个服务器. var http = require('http'); var server = http.createServer(); serve ...
- hdu_5879_Cure(打表)
题目链接:hdu_5879_Cure 题意: 给你一个n,让你计算1/k2的和,k从1到n. 题解: 因为只保留5位小数,所以打个100W的表,比这个数大的直接输出最后一位就行了 #include&l ...
- AnimatorController动画遮罩
游戏中,我们的人物在某些时候,可能在一个时间点在做两件事,这样就需要同时播放两个动画,但我们肯定不能简单将其叠加,比如移动着开枪.攻击.挥手等等,那么在Unity中我们应该怎样实现这样的功能呢?且听我 ...