D2. Magic Powder - 2

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

题目大意:就是制作一个蛋糕需要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 二分的更多相关文章

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

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

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

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

  3. CodeForces 670D Magic Powder

    二分. 二分一下答案,然后验证一下. #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cst ...

  4. Codeforces 1117C Magic Ship (二分)

    题意: 船在一个坐标,目的地在一个坐标,每天会有一个风向将船刮一个单位,船也可以移动一个单位或不动,问最少几天可以到目的地 思路: 二分天数,对于第k天 可以分解成船先被吹了k天,到达坐标(x1+su ...

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

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

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

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

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

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

  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. Spark on Mesos部署

    一.Mesos的安装和部署 1.下载mesos源码和依赖包 部署环境 centOS 6.6 mesos-0.21.0 spark-1.4.1 因为mesos官方只提供源码,所以必须要自己进行编译安装使 ...

  2. CDC spyglass

    SoC中会有着几百的clock domains,millions的async data crossing. Glitch等cdc问题是netlist level simulation的主要目的. CD ...

  3. ThinkPHP讲解(四)——视图

    本次讲解主要以<ThinkPHP开发手册>中“模板”一章中讲解为主 在MainController.class.php中新建一个操作方法Test() namespace Home\Cont ...

  4. 查看linux的出错信息

    先执行:dmesg -c > /dev/null 该命令是把之前的一些信息删除,-c选项表示:Clear the ring buffer after first printing its con ...

  5. Ceph的客户端丢失文件夹的解决办法

    原来的解决办法 更新linux内核,使用linux内核级的mount方式,一段时间后将会在客户端看不到部分长期不使用的文件夹 更正后的解决办法 参考Ceph的客户端安装设置ceph-fuse方式挂载c ...

  6. CentOS:安装桌面GNOME图形化界面

    u盘安装dvd版的CentOS7后,没有桌面,浏览器也是黑框版的:如果需要桌面的话,下面三条命令即可:但是安装桌面后,系统会没有之前纯净: 1 安装Gnome包: sudo yum groupinst ...

  7. centos 6 7更改主机名 命令添加ip

    6:vi /etc/sysconfig/network 中hostname =主机名 vi /etc/hosts  添加127.0.0.1相应的主机名 7: hostnamectl set-hostn ...

  8. django templates学习使用记录

    可以在基本模板中多插入几个black来适应不同的布局

  9. 【JQGRID DOCUMENTATION】.学习笔记.4.Navigator

    Navigator是一个将查找或编辑记录的动作,变得非常容易达到用户交互特性.开发者可以创建自定义动作,也可以使用六个预定义的动作.jqGrid为预定义的动作提供icon button图形. 一组完整 ...

  10. anroid 查看签名信息的方法

    1.把app改成压缩文件 2.解压以后找到META-INF\CERT.RSA 3.在CMD命令行里面输入:  keytool -printcert -file  E:\META-INF\CERT.RS ...