codeforces 350 div2 D 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
思路:直接二分查找最大能制造的饼干数,把上界设的2*10^9+1;最后你可能相差1,判断一下;
(d-1直接暴力模拟就好了)
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<queue>
#include<algorithm>
#include<stack>
#include<cstring>
#include<vector>
#include<list>
#include<set>
#include<map>
using namespace std;
#define ll __int64
#define mod 1000000007
#define inf 999999999
//#pragma comment(linker, "/STACK:102400000,102400000")
int scan()
{
int res = , ch ;
while( !( ( ch = getchar() ) >= '' && ch <= '' ) )
{
if( ch == EOF ) return << ;
}
res = ch - '' ;
while( ( ch = getchar() ) >= '' && ch <= '' )
res = res * + ( ch - '' ) ;
return res ;
}
ll a[];
ll b[];
ll check(ll x,ll gg,ll y)
{
ll cha=;
for(ll i=;i<=x;i++)
{
if(a[i]*gg>b[i])
cha+=a[i]*gg-b[i];
if(cha>y)
return ;
}
return ;
}
int main()
{
ll x,y,z,i,t;
scanf("%I64d%I64d",&x,&y);
for(i=;i<=x;i++)
scanf("%I64d",&a[i]);
for(i=;i<=x;i++)
scanf("%I64d",&b[i]);
ll st=;
ll en=;
while(st<en)
{
ll mid=(st+en)>>;
if(check(x,mid,y))
st=mid+;
else
en=mid;
}
if(check(x,st,y))
printf("%I64d\n",st);
else
printf("%I64d\n",st-);
return ;
}
codeforces 350 div2 D 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 ...
- Codefroces D2. Magic Powder - 2(二分)
http://codeforces.com/problemset/problem/670/D2 http://codeforces.com/problemset/problem/670/D1 time ...
- CodeForces 670D2 Magic Powder - 2 (二分)
题意:今天我们要来造房子.造这个房子需要n种原料,每造一个房子需要第i种原料ai个.现在你有第i种原料bi个.此外,你还有一种特殊的原料k个, 每个特殊原料可以当作任意一个其它原料使用.那么问题来了, ...
- codeforces#562 Div2 C---Increasing by modulo【二分】
题目:http://codeforces.com/contest/1169/problem/C 题意: 有n个数,每次可以选择k个,将他们+1并对m取模.问最少进行多少次操作,使得序列是非递减的. 思 ...
- codeforces 350 div2 C. Cinema map标记
C. Cinema time limit per test 2 seconds memory limit per test 256 megabytes input standard input out ...
- 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 ...
- Codeforces 670D1. Magic Powder - 1 暴力
D1. Magic Powder - 1 time limit per test: 1 second memory limit per test: 256 megabytes input: stand ...
- D2 Magic Powder -1/- 2---cf#350D2(二分)
题目链接:http://codeforces.com/contest/670/problem/D2 This problem is given in two versions that differ ...
随机推荐
- ssm后台开发及发布
本文详细讲解一下后台的创建及发布过程,包括踩过的坑 1:首先创建war包形式的maven工程 File>new>Maven project>Create a simple proje ...
- openstack部署心得
官方文档:https://docs.openstack.org/ 个别版本有中文 不要轻易尝试最新版本 新版本刚推出一般存在不少BUG或者文档没有更新,按照文档配置就是不能成功.推荐尝试最新版本的上一 ...
- testng入门教程13同文件数据驱动
下面是@DataProvider有name和没有name时 有name的时候可以引用name 即:@DataProvider(name="testData")----------& ...
- linux命令:linux文件处理命令
命令格式 : 命令 [-选项] [参数] 例:ls -la /etc 说明:1)个别命令使用不遵循此格式,[]代表可选 2)当有多个选项时,可以写在一起 3)-a等于 --all,调用简化选项用 ...
- CUDA显卡运算编程菜鸟入门指南1——Hello world - yfszzx的专栏 - 博客频道 - CSDN.NET
第一次知道有显卡(GPU)编程这个东西,是去年比特币最热门的时候,看了几篇关于比特币的文章,说比特币挖矿要靠显卡,CPU的速度与GPU根本就没法比,于是就非常好奇,显卡是什么神奇的东西?为什么运算速度 ...
- Django初级手册4-表单与通用视图
表单的编写 1. detail.html模版的编写 <h1>{{ poll.question }}</h1> {% if error_message %}<p>&l ...
- JSON—fastJSON
FastJSON的简介和作用? 1:基于java实现的JSON解析器和生成器 2:将java对象序列化成JSON字符串 3:将JSON字符串反序列化得到java对象 (在服务端生成java是很麻烦的事 ...
- transition和animation区别
Transform:对元素进行变形: Transition:对元素某个属性或多个属性的变化,进行控制(时间等),类似flash的补间动画.但只有两个关键贞.开始,结束. Animation:对元素某个 ...
- linux常用命令:yum 命令
用于添加/删除/更新RPM包,自动解决包的依赖问题以及系统更新升级. 1.命令格式: yum [参数] [软件名]2.命令功能: 功能: yum提供了查找.安装.删除某一个.一组甚至全 ...
- ajax return true/false无效原因
错误示例:function checkCP(customerId,productId){ $.ajax({ url:"/cp/checkCP", type:"post&q ...