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. centos7.x86_64搭建饥荒服务器

    http://blog.ttionya.com/article-1233.html 在centos7下找不到 libcurl-gnutls.so.4,而且必须要安装32位的才行 yum install ...

  2. ShopEx文章页添加上一篇下一篇功能

    在全部的文章页中,会常常发现都会有这么一个功能.能引导用户去查看上一篇文章或下一篇文章,而在ShopEx中,我DEZEND了一下文章模型.并没有找到上一篇这种函数功能,因此,这就须要我们手动在相应的文 ...

  3. pig 调试(explain&amp;illerstrate)

    grunt> cat t.txt kw1 2 kw3 1 kw2 4 kw1 5 kw2 2 cat test.pig A = LOAD '/user/input/t.txt' as (k:ch ...

  4. vim 插件之vim-trailing-whitespace

    vim-trailing-whitespace 这个插件是快速去掉文章行末的空格 地址 http://github.com/bronson/vim-trailing-whitespace 如果你想要使 ...

  5. 各大CMS系统优缺点(2017)

    各大CMS系统优缺点(2017) 总结 WordPress之前用过,可能需要再完整的用一个才会比较了解. 从2015年各行业建站规模来看,还有一大批人想自己搭建网站,下面为大家盘点一下比较实用CMS系 ...

  6. 机器学习规则:ML工程最佳实践----rule_of_ml section 3【翻译】

    作者:黄永刚 ML Phase III: 缓慢提升.精细优化.复杂模型 第二阶段就已经接近结束了.首先你的月收益开始减少.你开始要在不同的指标之间做出平衡,你会发现有的涨了而有的却降了.事情变得有趣了 ...

  7. Framework3.5安装(Windows8.1)

    在用到Android逆向助手,使用时提示安装Framework3.5,Windows7都有Framework3.5,Windows8却没有,联网更新就算了,这龟速更新得多久.但是问题总还是要解决,随便 ...

  8. Method Swizzing中一般替换方法都写在Category类别里吗?有没有别的实现方式

    Method Swizzing中一般替换方法都写在Category类别里吗?有没有别的实现方式 Method Swizzing中一般替换方法都写在Category类别里吗?有没有别的实现方式 > ...

  9. EasyUI 之 DataGrid利用用拉姆达表达式实现分页查询

      首先,我们在DataGrid的URL中加上我们要查询的条件:查询用户名不是“呵呵”的所有用户. <div> <table id="dg" class=&quo ...

  10. Input Team

    The Chromium Input team (aka input-dev) is a web platform team focused on making touch (P1) and othe ...