CodeForces 670D2 Magic Powder 二分
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
题目大意:就是制作一个蛋糕需要n种材料,然后你有k克魔法粉,每克魔法粉可以代替任意一克的材料,ai代表制作一个蛋糕需要第i种材料多少克,bi代表你拥有第i个材料多少克,问做多可以做多少个蛋糕。
题解:二分查找可以制作多少个蛋糕,假如可以制作,那么每一种材料都必须充足。
#include<stdio.h>
const int maxn= * 1e9 + ;
__int64 n, t, a[], b[];
__int64 f(__int64 z,__int64 y)
{
__int64 mid, sum;
int i;
while(z<=y)
{
mid=(z+y)/;
for(sum=,i=;i<=n;i++)
{
if(b[i]<a[i]*mid)
sum += (a[i]*mid-b[i]);
if(sum>t)
break;
}
if(sum==t)
return mid;
else if(sum<t)
z=mid+;
else
y=mid-;
}
return z-;
}
int main()
{
int i, j;
scanf("%d%d", &n, &t);
for(i=;i<=n;i++)
scanf("%d", &a[i]);
for(j=;j<=n;j++)
scanf("%d", &b[j]);
printf("%I64d\n", f(, maxn)); return ;
}
CodeForces 670D2 Magic Powder 二分的更多相关文章
- CodeForces 670D2 Magic Powder - 2 (二分)
		
题意:今天我们要来造房子.造这个房子需要n种原料,每造一个房子需要第i种原料ai个.现在你有第i种原料bi个.此外,你还有一种特殊的原料k个, 每个特殊原料可以当作任意一个其它原料使用.那么问题来了, ...
 - Codeforces 670D1. Magic Powder - 1 暴力
		
D1. Magic Powder - 1 time limit per test: 1 second memory limit per test: 256 megabytes input: stand ...
 - CodeForces 670D Magic Powder
		
二分. 二分一下答案,然后验证一下. #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cst ...
 - Codeforces 1117C Magic Ship (二分)
		
题意: 船在一个坐标,目的地在一个坐标,每天会有一个风向将船刮一个单位,船也可以移动一个单位或不动,问最少几天可以到目的地 思路: 二分天数,对于第k天 可以分解成船先被吹了k天,到达坐标(x1+su ...
 - 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 350 div2 D Magic Powder - 2 二分
		
D2. Magic Powder - 2 time limit per test 1 second memory limit per test 256 megabytes input standard ...
 - Codefroces  D2. Magic Powder - 2(二分)
		
http://codeforces.com/problemset/problem/670/D2 http://codeforces.com/problemset/problem/670/D1 time ...
 - 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 ...
 - D2 Magic Powder -1/- 2---cf#350D2(二分)
		
题目链接:http://codeforces.com/contest/670/problem/D2 This problem is given in two versions that differ ...
 
随机推荐
- Android -- 初探MVP模式
			
1,相信大家对mvp模式都很熟悉了,M-Model-模型.V-View-视图.C-Controller-控制器.MVP作为MVC的版本演化,与MVC的意义类似:M-Model-模型.V-View-视图 ...
 - spark sql cache
			
1.几种缓存数据的方法 例如有一张hive表叫做activity 1.CACHE TABLE //缓存全表 sqlContext.sql("CACHE TABLE activity" ...
 - webpack  无法安装
			
命令行输入: npm install webpack -g 解决办法:增加环境变量 D:\nine\trunk\node_modules\.bin\ bin目录下有webpack.cmd 如果还是 ...
 - 夺命雷公狗—angularjs—12—get参数的接收
			
我们在实际的开发中get和post的交互都是离不开的,我们先来研究下get参数是如何接收到的.. 而且在实际开发中利用json来进行传递参数也是比较多的,这里我们就以get来接收参数为列.. 先创建一 ...
 - sql server中index的REBUILD和REORGANIZE
			
参考文献: http://technet.microsoft.com/en-us/library/ms188388.aspx 正文 本文主要讲解如何使用alter index来rebuild和reor ...
 - Elasticsearch多索引
			
在Elasticsearch中,一般的查询都支持多索引.只有文档API或者别名API等不支持多索引操作,因此本篇就翻译一下多索引相关的内容. 首先,先插入几条数据: $ curl -XPOST lo ...
 - shell 日期加减
			
shell 日期加减运算 比如今日是2012-04-22 $ date -d "+1 day" +%Y-%m-%d 2012-04-23 $ date -d "- ...
 - Delphi 的各版本定义,用于预编译参数中,避免忘记备忘之
			
DELPHI的版本宏: VER80 - Delphi 1 VER90 - Delphi 2 VER100 - Delphi 3 VER120 - Delphi 4 VER130 - Delphi 5 ...
 - iOS发布条款检查表
			
序号 分类 条款编号 条款 案例 1 功能 2.1 崩溃的程序将会被拒绝 2 2.2 有错误的程序将会被拒绝 点击版本升级无反应/点击版本升级,在线版本和当前版本都是2.0.3 3 2.3 跟开发者宣 ...
 - CasperJS基于PhantomJS抓取页面
			
CasperJS基于PhantomJS抓取页面 Casperjs是基于Phantomjs的,而Phantom JS是一个服务器端的 JavaScript API 的 WebKit. CasperJS是 ...