Codefroces D2. Magic Powder - 2(二分)
http://codeforces.com/problemset/problem/670/D2
http://codeforces.com/problemset/problem/670/D1
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<iostream>
using namespace std;
int binary_search(int a[],int l,int r,int k)
{
int mid,ans;
while(l<=r)
{
mid=(l+r)>>1;
if(a[mid]<=k){
l=mid+1;
ans=mid;
}
else r=mid-1;
}
return ans;//也可ans+n;
}
int main()
{
int a[11]={1,2,4,7,7,7,7,8,10,11};
cout<<binary_search(a,0,9,4)<<endl;
return 0;
}
题解
#include<iostream>
#include<cstdio>
using namespace std;
long long a[],b[];
int main()
{
long long n,k,i;
scanf("%lld%lld",&n,&k);
for(i=;i<n;i++)
{
scanf("%lld",&a[i]);
}
for(i=;i<n;i++)
{
scanf("%lld",&b[i]);
}
long long l=,r=;
while(l<=r)
{
long long mid=(l+r)>>;
long long sum=;
for(i=;i<n;i++)
{
if(mid*a[i]>b[i]) sum+=(mid*a[i]-b[i]);
if(sum>k) break;
}
if(sum<=k) l=mid+;
else r=mid-;
}
printf("%lld",l-);
return ;
}
Codefroces D2. Magic Powder - 2(二分)的更多相关文章
- codeforces 350 div2 D Magic Powder - 2 二分
D2. Magic Powder - 2 time limit per test 1 second memory limit per test 256 megabytes input standard ...
- D2 Magic Powder -1/- 2---cf#350D2(二分)
题目链接:http://codeforces.com/contest/670/problem/D2 This problem is given in two versions that differ ...
- 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 670D2 Magic Powder - 2 (二分)
题意:今天我们要来造房子.造这个房子需要n种原料,每造一个房子需要第i种原料ai个.现在你有第i种原料bi个.此外,你还有一种特殊的原料k个, 每个特殊原料可以当作任意一个其它原料使用.那么问题来了, ...
- CodeForces 670D2 Magic Powder 二分
D2. Magic Powder - 2 The term of this problem is the same as the previous one, the only exception — ...
- Codeforces Round #350 (Div. 2)_D2 - Magic Powder - 2
D2. Magic Powder - 2 time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Magic Powder - 2 (CF 670_D)
http://codeforces.com/problemset/problem/670/D2 The term of this problem is the same as the previous ...
- Codeforces 670D1. Magic Powder - 1 暴力
D1. Magic Powder - 1 time limit per test: 1 second memory limit per test: 256 megabytes input: stand ...
随机推荐
- python学习--导入自己的包
定义一个自己的方法包: def myFunc(x): if x > 10: return x else: return -x 在需要的地方导入包: # 导入自定义的方法包 from learn ...
- 【Henu ACM Round#24 B】Gargari and Bishops
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 如果写过n皇后问题. 肯定都知道 某个点(i,j)和它在同一条对角线上的点分别是i+j的值和i-j的值相同的点. 然后会发现选择的两 ...
- mac和iphone处理视频
今天在微信上面发现有视频打不开,也无法下载到相册 而到电脑上可以打开 搜了一下,发现格式不对,mp4有很多格式,有的是苹果支持不了的. 要下载一个转换器,我下载了“超级转霸”,然后把视频转成了ipho ...
- [Transducer] Lazyness in Transduer
Transducers remove the requirement of being lazy to optimize for things like take(10). However, it c ...
- 实现浮点数的四舍五入RoundOff,保留几位小数
直接上代码,非常简短 double myRound(double d,int n) { d = d*pow(10,n); d += 0.5; d = (long)d; d = d/pow(10,n); ...
- POJ 2570 Fiber Network(最短路 二进制处理)
题目翻译 一些公司决定搭建一个更快的网络.称为"光纤网". 他们已经在全世界建立了很多网站.这 些网站的作用类似于路由器.不幸的是,这些公司在关于网站之间的接线问题上存在争论,这样 ...
- nyoj914(二分搜索+贪心)
题目意思: pid=914">acm.nyist.net/JudgeOnline/problem.php?pid=914 如今有n个物品的重量和价值各自是Wi和Vi,你能帮他从中选出k ...
- OC中的@的作用研究
OC中的@字符用的频率很的高,其主要作用是为了差别于其它语言的keyword和语法 以下我们来研究一下其应用 1.声明类,协议,延展,权限,属性等 @interface声明类 @protocol声明协 ...
- excle查找操作-vlookup的使用心得
百度了一下vlookup的语法规则: 该函数的语法规则例如以下: VLOOKUP(lookup_value,table_array,col_index_num,range_lookup) 參数 简单说 ...
- A string is a sequence
A string is a sequence of characters. You can access the characters one at a time with the bracket o ...