Codeforces 670D2 Magic Powder - 2 二分答案
来源:互联网 发布:淘宝图库 编辑:程序博客网 时间:2024/05/16 11:47
Waking up in the morning, Apollinaria decided to bake cookies. To bake one cookie, she needs n ingredients, and for each ingredient she knows the value ai — how many grams of this ingredient one needs to bake a cookie. To prepare one cookie Apollinaria needs to use all n ingredients.
Apollinaria has bi gram of the i-th ingredient. Also she has k grams of a magic powder. Each gram of magic powder can be turned to exactly 1 gram of any of the n ingredients and can be used for baking cookies.
Your task is to determine the maximum number of cookies, which Apollinaria is able to bake using the ingredients that she has and the magic powder.
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.
分析:
二分答案即可。
#include <bits/stdc++.h>using namespace std;typedef long long ll;const int N=1e5+9;ll a[N],b[N];int n,k;bool ok(ll x){ ll num=k; for(int i=0;i<n;i++){ ll t=b[i]-x*a[i]; if(t<0){ num+=t; if(num<0)return 0; } } return 1;}int main(){ scanf("%d%d",&n,&k); for(int i=0;i<n;i++)scanf("%I64d",&a[i]); for(int i=0;i<n;i++)scanf("%I64d",&b[i]); ll l=0,r=2e9+9; while(l<r){ int m=l+(r-l+1)/2; if(ok(m))l=m; else r=m-1; } printf("%d\n",l);}
- Codeforces 670D2 Magic Powder - 2 二分答案
- Codeforces Round #350 (Div. 2) D2. Magic Powder - 2 670D 【二分答案】
- CodeForces 670D2 Magic Powder - 2(二分+贪心)
- CodeForces - 670D2 Magic Powder - 2 (二分&模拟)
- 【CodeForces】670D2 - Magic Powder - 2(二分)
- Codeforces 670D2:Magic Powder - 2(二分)
- codeforces 670D2. Magic Powder - 2
- codeforces 670D2 - Magic Powder - 2
- CodeForces 670D2 Magic Powder - 2
- 【CodeForces】[670D2]Magic Powder - 2
- CodeForces 670D2 Magic Powder - 2
- Codeforces 670D2 Magic Powder-2
- Codeforces 670D2 Magic Powder
- Codeforces Round #350 (Div. 2) D2 Magic Powder - 2【二分】
- Codeforces Round #350 (Div. 2) D2. Magic Powder - 2 【二分】
- cf 670D2 Magic Powder - 2 二分裸题
- D2. Magic Powder - 2
- coderforces 670D2 Magic Powder - 2
- JavaScript history 对象
- Oracle数据库-表管理
- Marklogic学习 由浅入深(8)—— 第一个Marklogic应用(上)
- Python组合的实例用法
- Agri-Net(最小生成树)
- Codeforces 670D2 Magic Powder - 2 二分答案
- ReactiveCocoa 学习笔记 - 使用篇
- 二叉树的链式实现(插入,查找,遍历,删除)
- 信息管理系统的登录注册
- 黑帽SEO中的蜘蛛池是什么?
- 347. Top K Frequent Elements
- 停止线程
- open glHelloWorld之旋转的三角形(android)
- ios 开发学习日志 自定义alertView 1