Magic Powder - 2 (CF 670_D)
http://codeforces.com/problemset/problem/670/D2
The term of this problem is the same as the previous one, the only exception — increased restrictions.
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.
Print the maximum number of cookies, which Apollinaria will be able to bake using the ingredients that she has and the magic powder.
1 1000000000
1
1000000000
2000000000
10 1
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000
1 1 1 1 1 1 1 1 1 1
0
3 1
2 1 4
11 3 16
4
4 3
4 3 5 6
11 12 14 20
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)的更多相关文章
- 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 ...
- I - Magic FZU - 2280 (字符串hash)
题目链接: I - Magic FZU - 2280 学习链接: FZU - 2280 I - Magic 题目大意: 给你nn个字符串,每个字符串有一个值ww,有qq次询问,一共两种操作:一是“1, ...
- Mike and Feet(CF 547B)
Mike and Feet time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- 2019.4.24 一题(CF 809E)——推式子+虚树
题目:http://codeforces.com/contest/809/problem/E
- (求凹包) Bicycle Race (CF 659D) 简单题
http://codeforces.com/contest/659/problem/D Maria participates in a bicycle race. The speedway t ...
- 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 ...
- 线段树题集 (cf版)
lazy区间修改 : http://acm.hdu.edu.cn/showproblem.php?pid=4902 (hdu4902) http://acm.hdu.edu.cn/showpr ...
- 聚类算法之BIRCH(Java实现)转载
http://www.cnblogs.com/zhangchaoyang/articles/2200800.html http://blog.csdn.net/qll125596718/article ...
- 固态硬盘SSD与闪存(Flash Memory)
转自:http://qiaodahai.com/solid-state-drives-ssd-and-flash-memory.html 固态硬盘SSD(Solid State Drive)泛指使用N ...
随机推荐
- otool
一.简介 二.实例 1)查看动态链接库 otool -L /usr/bin/vim
- html标签三
1.下拉框和下拉表框 <select name="" id="" multiple> <option value="xx" ...
- PHP 文件操作代码
<?php //echo filetype("./1.jpg"); //判断文件类型 文件:file //echo filetype("./code"); ...
- Python Json模块中dumps、loads、dump、load函数介绍
1.json.dumps() json.dumps()用于将dict类型的数据转成str,因为如果直接将dict类型的数据写入json文件中会发生报错,因此在将数据写入时需要用到该函数. import ...
- Using The jQuery Migrate Plugin
jQuery( html [, ownerDocument ] )Returns: jQuery Description: Creates DOM elements on the fly from t ...
- jquery或者JavaScript调用WCF服务的方法
/****************************************************************** * Copyright (C): 一心堂集团 * CLR版本: ...
- 【UI测试】--美观与协调性
- EditText输入小数
edtValue.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);
- canvas 实现烟花效果
一:创建画布 <canvas width="600" height="600" id="canvas" style="bor ...
- 前端之javascript的数据类型1和BOM对象
一 js对象 BOM对象:browser object model浏览器模型对象 window对象:定时器 DOM对象:文档对象模型 js对象:字符串对象,数组对象,日期对象,math对象 new关键 ...