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. 常用的pdf工具

    https://www.ilovepdf.com/zh-cn https://smallpdf.com/cn/compress-pdf https://www.pdf2go.com/zh/compre ...

  2. [转载]不唐突的JavaScript的七条准则

    经过多年的开发.教学和编写不唐突的JavaScript, 我发现了下面的一些准则.我希望它们可以帮助你对“为什么这样设计和执行JavaScript比较好”有一点理解.这些规则曾经帮助我更快地交付产品, ...

  3. Datazen图表创建和公布

     Datazen是被微软收购的移动端全平台的数据展现解决方式.此篇主要介绍怎样创建和公布图表. 如前面介绍,Datazen图表的创建和公布是通过Publisher的应用,它是Windows 8应用 ...

  4. Linux多线程实践(六)使用Posix条件变量解决生产者消费者问题

    前面的一片文章我们已经讲过使用信号量解决生产者消费者问题.那么什么情况下我们须要引入条件变量呢? 这里借用  http://www.cnblogs.com/ngnetboy/p/3521547.htm ...

  5. 11_HTML5_Local_Storage本地存储

    本地存储localStorage是大型cookie,cookie只有4k,

  6. Cms WebSite 编译非常慢

    第一次编译非常慢 如果遇到错误,中途中断的话. 下一次编译的时候,上一次已经编译过的文件,会非常快的略过.很快就会到上一次遇到错误的地方,继续往下进行编译.

  7. WHERE、ORDER BY、GROUP BY、HAVING语句解析(二十八)

    之前啊,我们提及到,对于update和delete,若不带where条件,则对所有记录都有效. 一.WHERE条件表达式 (1)对记录进行过滤,如果没有指定WHERE子句,则显示所有记录. (2)在W ...

  8. 【DNN 系列】 下载安装

    1.下载 http://dotnetnuke.codeplex.com/releases/view/119857 2.安装 下载完毕 因为 IIS 7 采用了更安全的 web.config 管理机制, ...

  9. 一些 <link> 标记分享

    <link rel="alternate" media="handheld" href="#" /> <link rel= ...

  10. HDU 1240 Asteroids!【BFS】

    题意:给出一个三维的空间,给出起点和终点,问是否能够到达终点 和上一题一样,只不过这一题的坐标是zxy输入的, 因为题目中说的是接下来的n行中分别是由n*n的矩形组成的,所以第一个n该是Z坐标,n*n ...