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 ...
随机推荐
- log4net 使用教程
1.下载log4net (Google log4net) //已有 2.unzip log4net 3.运行VS,新建 c# Windows应用程序. 4.添加引用Log4NET 5.新建一个应用程序 ...
- angular form 验证 ngMessage
<!DOCTYPE HTML> <html ng-app="deliciousApp"> <head> <meta charset=&qu ...
- an'gularjs 环境搭建之NodeJS、NPM安装配置步骤(windows版本)
NodeJS.NPM安装配置步骤(windows版本) :http://xiaoyaojones.blog.163.com/blog/static/28370125201351501113581/ ...
- android 项目学习随笔二十一(IM、语音识别、机器人、统计、扫描二维码、条形码)
语音识别:科大讯飞语音云 http://www.xfyun.cn/ 语音机器人模拟 public class TalkBean { public String text; public boolean ...
- exe文件打开方式(恢复EXE文件关联)
文件关联损坏常常是计算机病毒造成的,目前网络上有很多相关修复工具,相对来说,System Repair Engineer 支持的修复格式是比较齐全的,这个工具可以在http://www.kztechs ...
- javaWeb el表达式和jstl快速入门案例
<%@page import="de.bvb.domain.Person"%> <%@page import="de.bvb.domain.Addres ...
- web.xml完整配置
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://java ...
- html5 canvas 笔记三(绘制文本和图片)
绘制文本 fillText(text, x, y [, maxWidth]) 在指定的(x,y)位置填充指定的文本,绘制的最大宽度是可选的. strokeText(text, x, y [, ma ...
- PHP获取不了React Native Fecth参数的解决办法是怎么样呢?
fetch('https://mywebsite.com/endpoint/', { method: 'POST',headers: {'Accept': 'application/json','Co ...
- java 堆栈 静态
所以静态变量和非静态变量的区别就在于静态变量可以用来计数,而非静态变量则不行. 理解了内存,就理解了一切,就理解了各种各样的语言.所有的语言无非都是这样:局部变量分配内存永远在栈里面,new出来的东西 ...