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 ...
随机推荐
- 文章如何做伪原创 SEO大神教你几招做"原创"网站文章的心得
想要创作出好的文章并被百度所喜欢,就非常需要SEO的优化能力,以及要对文章进行塬创或伪塬创,那么,如何做伪塬创文章?以及如何做好塬创网站文章呢?对此,本文小编就为大家带来了几招做"塬创&qu ...
- 比较两个List列表,取得List中不同项返回
/// <summary> /// 比对模型及属性数组 /// </summary> /// <typeparam name="TM">< ...
- MS-Office使用技巧
1.角标设置 下角标:选中(Shift+左右方向键)-->Ctrl+= 上角标:选中(Shift+左右方向键)-->Ctrl+Shift+=(Ctrl++) 撤销:同样操作 2.MS Of ...
- go语言字符串练习
package main import "fmt" import s"strings" var p = fmt.Println func main() { p( ...
- Subarray Sum Equals K LT560
Given an array of integers and an integer k, you need to find the total number of continuous subarra ...
- 全面了解HTTP请求方法说明
超文本传输协议(HTTP, HyperText Transfer Protocol)是一种无状态的协议,它位于OSI七层模型的传输层.HTTP客户端会根据需要构建合适的HTTP请求方法,而HTTP服务 ...
- windows mysql 主从热备
环境说明: Master:192.168.1.200 Slave:192.168.1.210 MySQL 的 Master 配置: 配置my.ini: [mysqld] # T ...
- js 分页
html代码: <div id="paging_wrap" class="paging-wrap"></div> css代码: div ...
- MySQL基准测试--innodb_buffer_pool_instances
http://blog.chinaunix.net/uid-26896862-id-3345441.html 目的 根据现有硬件环境下,测试MySQL单实例下,在数据量小于innodb_buffer_ ...
- BP神经网络的理论理论常识
BP神经网络的简单结构:输入层.一个或者多个隐层.输出层.图如下: 在图中,涉及到的参数有:X1--Xn为输入参数.输入参数通过输入层和隐层之间的的链接权重进行计算,到达隐层. 隐层的输入参数通过隐层 ...