Codeforces 670 D1. Magic Powder - 1【二分查找】
来源:互联网 发布:怎样兼职网络授课教师 编辑:程序博客网 时间:2024/04/29 21:06
This problem is given in two versions that differ only by constraints. If you can solve this problem in large constraints, then you can just write a single solution to the both versions. If you find the problem too difficult in large constraints, you can write solution to the simplified version only.
Waking up in the morning, Apollinaria decided to bake cookies. To bake one cookie, she needsn ingredients, and for each ingredient she knows the valueai — how many grams of this ingredient one needs to bake a cookie. To prepare one cookie Apollinaria needs to use alln ingredients.
Apollinaria has bi gram of thei-th ingredient. Also she has k grams of a magic powder. Each gram of magic powder can be turned to exactly1 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.
The first line of the input contains two positive integers n and k (1 ≤ n, k ≤ 1000) — the number of ingredients and the number of grams of the magic powder.
The second line contains the sequence a1, a2, ..., an (1 ≤ ai ≤ 1000), where the i-th number is equal to the number of grams of thei-th ingredient, needed to bake one cookie.
The third line contains the sequence b1, b2, ..., bn (1 ≤ bi ≤ 1000), where the i-th number is equal to the number of grams of thei-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.
In the first sample it is profitably for Apollinaria to make the existing 1 gram of her magic powder to ingredient with the index 2, then Apollinaria will be able to bake 4 cookies.
In the second sample Apollinaria should turn 1 gram of magic powder to ingredient with the index1 and 1 gram of magic powder to ingredient with the index3. Then Apollinaria will be able to bake 3 cookies. The remaining 1 gram of the magic powder can be left, because it can't be used to increase the answer.
#include<stdio.h>#include<string.h>using namespace std;int need[1008];int have[1008];int tmpp[1008];int n,k;int Slove(int mid){ for(int i=1;i<=n;i++) { tmpp[i]=have[i]-mid*need[i]; } int sum=0; for(int i=1;i<=n;i++) { if(tmpp[i]<0)sum+=-tmpp[i]; } if(sum<=k)return 1; else return 0;}int main(){ while(~scanf("%d%d",&n,&k)) { for(int i=1;i<=n;i++) { scanf("%d",&need[i]); } for(int i=1;i<=n;i++) { scanf("%d",&have[i]); } int ans=0; int mid; int l=0; int r=10000; while(r>=l) { mid=(l+r)/2; if(Slove(mid)==1) { ans=mid; l=mid+1; } else { r=mid-1; } } printf("%d\n",ans); }}
- Codeforces 670 D1. Magic Powder - 1【二分查找】
- codeforces 670D1 - Magic Powder - 1
- D - Magic Powder - 1 codeforces 670d1
- codeforces 670D1 Magic Powder - 1
- CodeForces - 670D1 Magic Powder - 1 (模拟)
- CodeForces 670D2 Magic Powder - 2(二分+贪心)
- Codeforces 670D2 Magic Powder - 2 二分答案
- CodeForces - 670D2 Magic Powder - 2 (二分&模拟)
- 【CodeForces】670D2 - Magic Powder - 2(二分)
- CodeForces 670D Magic Powder - 2 (二分)
- Codeforces 670D2:Magic Powder - 2(二分)
- Codeforces 670D2 Magic Powder
- Codeforces Round #350 (Div. 2) D1,D2Magic Powder(二分)
- 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
- ionic-文件下载指令
- HDU 1069 Monkey and Banana (经典dp)详解及易错点分析
- 2万名俱乐部
- 分蛋糕问题 —— 9 个烧饼分给 10 个人
- Genymotion 安装项目失败
- Codeforces 670 D1. Magic Powder - 1【二分查找】
- JSP个人理解
- android中如何显示开发者服务器上的昵称和头像
- actionscript(flash)和java后台的数据交互!
- Android中Paint的setXfermode(Xfermode xfermode)方法讲解
- 自己了解的Spring
- 模板 容器
- log 控制
- ORACLE开发触发器