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

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 <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
using namespace std; #define N 110000
#define met(a, b) memset(a, b, sizeof(a))
#define INF 0x3f3f3f3f
const long long Max = ;
typedef long long LL; LL a[N], b[N];
LL n, k; LL Judge(LL mid)
{
LL i, K1=k, K2=k; for(i=; i<=n; i++)
{
if(b[i]<a[i]*mid)
{
K1 -= (a[i]*mid - b[i]);
if(K1<)
return -;
}
} for(i=; i<=n; i++)
{
if(b[i]<a[i]*(mid+))
{
K2 -= (a[i]*(mid+) - b[i]);
if(K2<)
return ;
}
} return ;
} int main()
{ while(scanf("%I64d%I64d", &n, &k)!=EOF)
{
LL i;
LL mid, L=, R=Max, ans; met(a, );
met(b, ); for(i=; i<=n; i++)
scanf("%I64d", &a[i]);
for(i=; i<=n; i++)
scanf("%I64d", &b[i]); while(L<R)
{
mid = (L+R)/;
ans = Judge(mid);
if(ans==)
L = R = mid;
if(ans>)
L = mid + ;
if(ans<)
R = mid - ;
} printf("%I64d\n", L);
} return ;
}

Magic Powder - 2 (CF 670_D)的更多相关文章

  1. 2013 多校联合 F Magic Ball Game (hdu 4605)

    http://acm.hdu.edu.cn/showproblem.php?pid=4605 Magic Ball Game Time Limit: 10000/5000 MS (Java/Other ...

  2. I - Magic FZU - 2280 (字符串hash)

    题目链接: I - Magic FZU - 2280 学习链接: FZU - 2280 I - Magic 题目大意: 给你nn个字符串,每个字符串有一个值ww,有qq次询问,一共两种操作:一是“1, ...

  3. Mike and Feet(CF 547B)

    Mike and Feet time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  4. 2019.4.24 一题(CF 809E)——推式子+虚树

    题目:http://codeforces.com/contest/809/problem/E

  5. (求凹包) Bicycle Race (CF 659D) 简单题

    http://codeforces.com/contest/659/problem/D     Maria participates in a bicycle race. The speedway t ...

  6. Magic Odd Square (思维+构造)

    Find an n × n matrix with different numbers from 1 to n2, so the sum in each row, column and both ma ...

  7. 线段树题集 (cf版)

    lazy区间修改   : http://acm.hdu.edu.cn/showproblem.php?pid=4902   (hdu4902) http://acm.hdu.edu.cn/showpr ...

  8. 聚类算法之BIRCH(Java实现)转载

    http://www.cnblogs.com/zhangchaoyang/articles/2200800.html http://blog.csdn.net/qll125596718/article ...

  9. 固态硬盘SSD与闪存(Flash Memory)

    转自:http://qiaodahai.com/solid-state-drives-ssd-and-flash-memory.html 固态硬盘SSD(Solid State Drive)泛指使用N ...

随机推荐

  1. otool

    一.简介   二.实例 1)查看动态链接库 otool -L /usr/bin/vim

  2. html标签三

    1.下拉框和下拉表框 <select name="" id="" multiple> <option value="xx" ...

  3. PHP 文件操作代码

    <?php //echo filetype("./1.jpg"); //判断文件类型 文件:file //echo filetype("./code"); ...

  4. Python Json模块中dumps、loads、dump、load函数介绍

    1.json.dumps() json.dumps()用于将dict类型的数据转成str,因为如果直接将dict类型的数据写入json文件中会发生报错,因此在将数据写入时需要用到该函数. import ...

  5. Using The jQuery Migrate Plugin

    jQuery( html [, ownerDocument ] )Returns: jQuery Description: Creates DOM elements on the fly from t ...

  6. jquery或者JavaScript调用WCF服务的方法

    /****************************************************************** * Copyright (C): 一心堂集团 * CLR版本: ...

  7. 【UI测试】--美观与协调性

  8. EditText输入小数

    edtValue.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);

  9. canvas 实现烟花效果

    一:创建画布 <canvas width="600" height="600" id="canvas" style="bor ...

  10. 前端之javascript的数据类型1和BOM对象

    一 js对象 BOM对象:browser object model浏览器模型对象 window对象:定时器 DOM对象:文档对象模型 js对象:字符串对象,数组对象,日期对象,math对象 new关键 ...