D2. Magic Powder - 2
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

The term of this problem is the same as the previous one, the only exception — increased restrictions.

Input

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.

Output

Print the maximum number of cookies, which Apollinaria will be able to bake using the ingredients that she has and the magic powder.

Examples
input
1 1000000000
1
1000000000
output
2000000000
input
10 1
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000
1 1 1 1 1 1 1 1 1 1
output
0
input
3 1
2 1 4
11 3 16
output
4
input
4 3
4 3 5 6
11 12 14 20
output
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 二分的更多相关文章

  1. Codeforces Round #350 (Div. 2) D1. Magic Powder - 1 二分

    D1. Magic Powder - 1 题目连接: http://www.codeforces.com/contest/670/problem/D1 Description This problem ...

  2. Codefroces D2. Magic Powder - 2(二分)

    http://codeforces.com/problemset/problem/670/D2 http://codeforces.com/problemset/problem/670/D1 time ...

  3. CodeForces 670D2 Magic Powder - 2 (二分)

    题意:今天我们要来造房子.造这个房子需要n种原料,每造一个房子需要第i种原料ai个.现在你有第i种原料bi个.此外,你还有一种特殊的原料k个, 每个特殊原料可以当作任意一个其它原料使用.那么问题来了, ...

  4. codeforces#562 Div2 C---Increasing by modulo【二分】

    题目:http://codeforces.com/contest/1169/problem/C 题意: 有n个数,每次可以选择k个,将他们+1并对m取模.问最少进行多少次操作,使得序列是非递减的. 思 ...

  5. codeforces 350 div2 C. Cinema map标记

    C. Cinema time limit per test 2 seconds memory limit per test 256 megabytes input standard input out ...

  6. CodeForces 670D2 Magic Powder 二分

    D2. Magic Powder - 2 The term of this problem is the same as the previous one, the only exception — ...

  7. 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 ...

  8. Codeforces 670D1. Magic Powder - 1 暴力

    D1. Magic Powder - 1 time limit per test: 1 second memory limit per test: 256 megabytes input: stand ...

  9. D2 Magic Powder -1/- 2---cf#350D2(二分)

    题目链接:http://codeforces.com/contest/670/problem/D2 This problem is given in two versions that differ ...

随机推荐

  1. [py]字符串/列表

    去除str首尾空格(切片) ## str长度 循环,判断 ### [:i] [i:] 记录位置点 ## 方法1 def trim2(s): s2 = "" start = 0 en ...

  2. Linux实验楼学习之一

    查看当前所在目录 pwd 创建文件:1-1.txt touch 1-1.txt 进入统计目录下的etc目录 cd /etc 强行终止当前程序 Ctrl + c 常用快捷键 按键 作用 Ctrl+d 键 ...

  3. Linux系统——MySQL基础(三)

    ### MySQL主从复制实践#### 主从复制实践准备(1)主从复制数据库实战环境准备MySQL主从复制实践对环境的要求比较简单,可以是单机单数据库多实例的环境,也可以是两台服务器,每个机器一个独立 ...

  4. ExtJs中XTemplate使用(转)

    转自http://www.studyofnet.com/news/408.html 本文导读:XTemplate是Ext.Template扩展的新类,它支持高级功能的模板类,如自动数组输出.条件判断. ...

  5. 形象易懂讲解算法I——小波变换

    https://zhuanlan.zhihu.com/p/22450818?refer=dong5 最早发于回答:能不能通俗的讲解下傅立叶分析和小波分析之间的关系? - 咚懂咚懂咚的回答现收入专栏. ...

  6. Oracle 启动的时候需要的服务

  7. MyBatis学习笔记(八)——Mybatis3.x与Spring4.x整合

    转自孤傲苍狼的博客:http://www.cnblogs.com/xdp-gacl/p/4271627.html 一.搭建开发环境 1.1.使用Maven创建Web项目 执行如下命令: mvn arc ...

  8. 斯坦福大学机器学习,EM算法求解高斯混合模型

    斯坦福大学机器学习,EM算法求解高斯混合模型.一种高斯混合模型算法的改进方法---将聚类算法与传统高斯混合模型结合起来的建模方法, 并同时提出的运用距离加权的矢量量化方法获取初始值,并采用衡量相似度的 ...

  9. python3.4学习笔记(二十五) Python 调用mysql redis实例代码

    python3.4学习笔记(二十五) Python 调用mysql redis实例代码 #coding: utf-8 __author__ = 'zdz8207' #python2.7 import ...

  10. java网络基础知识的简述

    TCP/UDP的介绍 TCP协议:面向连接的,字节流无差错地传输协议. UDP协议:一个不可靠的无连接的数据传输协议. 说明:TCP可以想象成电话通讯,双方在通话时必须建立连接,一方没听清,会要求对方 ...