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

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

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
二分模板
#include<iostream>
using namespace std;
int binary_search(int a[],int l,int r,int k)
{
    int mid,ans;
    while(l<=r)
    {
        mid=(l+r)>>1;
        if(a[mid]<=k){
            l=mid+1;
            ans=mid;
        }
        else r=mid-1;
    }
    return ans;//也可ans+n;
}
int main()
{
    int a[11]={1,2,4,7,7,7,7,8,10,11};
    cout<<binary_search(a,0,9,4)<<endl;
    return 0;
}

题解

#include<iostream>
#include<cstdio>
using namespace std;
long long a[],b[];
int main()
{
long long n,k,i;
scanf("%lld%lld",&n,&k);
for(i=;i<n;i++)
{
scanf("%lld",&a[i]);
}
for(i=;i<n;i++)
{
scanf("%lld",&b[i]);
}
long long l=,r=;
while(l<=r)
{
long long mid=(l+r)>>;
long long sum=;
for(i=;i<n;i++)
{
if(mid*a[i]>b[i]) sum+=(mid*a[i]-b[i]);
if(sum>k) break;
}
if(sum<=k) l=mid+;
else r=mid-;
}
printf("%lld",l-);
return ;
}

Codefroces D2. Magic Powder - 2(二分)的更多相关文章

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

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

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

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

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

  4. Codeforces Round #350 (Div. 2) D2. Magic Powder - 2

    题目链接: http://codeforces.com/contest/670/problem/D2 题解: 二分答案. #include<iostream> #include<cs ...

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

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

  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. Magic Powder - 2 (CF 670_D)

    http://codeforces.com/problemset/problem/670/D2 The term of this problem is the same as the previous ...

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

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

随机推荐

  1. 你的Android应用完全不需要那么多的权限

    Android系统的权限从用户的角度来看有时候的确有点让人摸不着头脑.有时候可能你只需要做一些简单的事情(对联系人的信息进行编辑),却申请了远超你应用所需的权限(比如访问所有联系人信息的权限). 这很 ...

  2. Swift环境下实现UILabel居上 居中 居下对齐

    首先在Xcode中新建.h文件,将下面代码复制进去 // // myUILabel.h // // // Created by yexiaozi_007 on 3/4/13. // Copyright ...

  3. 编译并使用boost库(win7+boost1.63+vs2015+32位or 64位),超详细,boost于vs2017下编译(64/32bit)

    首先下载得到boost的最新版(目前最新版是1.63) 下载地址: http://www.boost.org   也可以从这里直接下载 http://download.csdn.net/detail/ ...

  4. UVa 216 Getting in Line【枚举排列】

    题意:给出n个点的坐标,(2<=n<=8),现在要使得这n个点连通,问最小的距离的和 因为n很小,所以可以直接枚举这n个数的排列,算每一个排列的距离的和, 保留下距离和最小的那个排列就可以 ...

  5. healthcheck

    -- ============================================================================= -- USAGE  : sqlplus ...

  6. Debian9.5下ssh密钥登录配置步骤(免密码登录)和ssh-keygen 命令常用参数

    密钥登录步骤(免密码登录)ssh登录提供两种认证方式:口令(密码)认证方式和密钥认证方式.其中口令(密码)认证方式是我们最常用的一种,出于安全方面的考虑,介绍密钥认证方式登录到linux/unix的方 ...

  7. github下载速度慢解决方法

    1.获取 global.ssl.fastly地址 访问 http://github.global.ssl.fastly.net.ipaddress.com/#ipinfo 获取cdn域名以及ip地址  ...

  8. nginx配置虚拟域名

           /usr/lcoal/nginx/conf/nginx.conf 配置详解如下: worker_processes   1;                                ...

  9. 一:1.1 python程序与数据储存【进制转换】

    二进制 :0 1 [逢二进一]0+0=00+1=11+1=1011+1=100 1 1+ 1------ 100 八进制: 0 1 2 3 4 5 6 7 [逢八进一] 1+7=101+2=3 十进制 ...

  10. Android开发之Menu:OptionMenu(选项菜单)、ContextMenu(上下文菜单)、SubMenu(子菜单)

    菜单的概念,现在已经很普及了.Windows系统.Mac.桌面版Linux.Java Swing等,都有可视化菜单.一.Android平台3种菜单  选项菜单(OptionMenu).上下文菜单(Co ...