题目链接:http://codeforces.com/problemset/problem/670/D1

题目:Magic Powder - 1

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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 hask grams of a magic powder. Each gram of magic powder can be turned to exactly1 gram of any of then 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 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.

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
3 1
2 1 4
11 3 16

Output
4

Input
4 3
4 3 5 6
11 12 14 20

Output
3

Note

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 and1 gram of magic powder to ingredient with the index3. Then Apollinaria will be able to bake3 cookies. The remaining 1 gram of the magic powder can be left, because it can't be used to increase the answer.

题意:首先给出有n种原材料和k个魔法棒(一个魔法棒可变成任意原材料中任意一种中的的一份),接下来给出加工一件物品所需每种原材料的量,下面给出现在每种原材料所有量,求做多可以做出多少件物品

思路:数据要求不大,直接进行暴力求解

代码:

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <queue>
#include <cstring>
#include <stack>
using namespace std;int n,k;
int a[1005];
int b[1005];
struct point {int a;int b;int c;
} p[1005];int main() {cin >> n >> k;int maxn = 0xffffff;for(int i = 0; i < n; i++) {cin >> a[i];}for(int i = 0; i < n; i++) {cin >> b[i];p[i].a = b[i]/a[i];//获得这一样东西最大能够满足多少个p[i].b = b[i]%a[i];//获得剩余量p[i].c = a[i]-p[i].b;//获得补多少maxn = min(maxn,p[i].a);}while(true) {int i;for(i = 0; i < n; i++) {if(p[i].a == maxn) {//说明只有这种物品数量不够,需要补充if(k < p[i].c) {//魔法棒的数量不足以填充break;} else {k -= p[i].c;//魔法棒数量减少多少p[i].c = a[i];//说明下一次需要补的量p[i].a = maxn+1;//补一次这种的个数就加一保证下一次仍然要继续补}}}if(i == n) {maxn++;} else {break;}}cout << maxn << endl;return 0;
}

D2数据量变大以后直接对答案进行二分

AC代码:

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <queue>
#include <cstring>
#include <stack>
using namespace std;int n,k;
int a[100005];
int b[100005];bool ok(long long x) {long long s = k;for(int i = 0; i < n; i++) {if(x*a[i] >= b[i]) {s -= (x*a[i]-b[i]);}if(s < 0) {return false;}}return true;
}
int main() {cin >> n >> k;for(int i = 0; i < n; i++) {cin >> a[i];}for(int j = 0; j < n; j++) {cin >> b[j];}if(n == 1) {cout << (b[0]+k)/a[0] << endl;} else {int sum  =0;long long l = 0,r = 0xffffffff;long long mid;while(l <= r) {mid=(l+r)>>1;if(ok(mid)) {l = mid+1;sum = mid;} else {r = mid-1;}}cout << sum << endl;}return 0;
}

codeforces 670D1 Magic Powder - 1相关推荐

  1. CodeForces 670D2 Magic Powder - 2

    Description The term of this problem is the same as the previous one, the only exception - increased ...

  2. CodeForces 670D2 Magic Powder - 2(二分+贪心)

    http://codeforces.com/contest/670/problem/D2 简单的二分,二分所有可以做的饼干数,然后遍历就可以啦 #include <iostream> #i ...

  3. CodeForces 670D Magic Powder

    二分. 二分一下答案,然后验证一下. #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cst ...

  4. 【CodeForces - 670D1 】Magic Powder - 1 (模拟 或 枚举 或二分优化)

    题干: This problem is given in two versions that differ only by constraints. If you can solve this pro ...

  5. Magic Powder - 2

    https://codeforces.com/contest/670/problem/D2 The term of this problem is the same as the previous o ...

  6. Magic Powder - 2 (CF 670_D)

    http://codeforces.com/problemset/problem/670/D2 The term of this problem is the same as the previous ...

  7. codeforce之Magic Powder

    题目: The term of this problem is the same as the previous one, the only exception - increased restric ...

  8. Magic Powder - 1,2

    问题 This problem is given in two versions that differ only by constraints. If you can solve this prob ...

  9. Magic Powder - 1 CodeForces - 670D1(优先队列进一步理解)

    写这个题的时候一直在想怎么才能动态排序(一遍改变数值,一遍从新改变相应的顺序),到最后才突然想起来这不就是优先队列吗,通过这题对优先队列的动态排序有了进一步理解.好题! AC代码: #include ...

最新文章

  1. [Buzz.Today]2011.05.25
  2. 关于Iframe之间以及与父窗体的值传递
  3. Linux下安装和使用boost库
  4. 异常数据4种剔除方法_数据分析系列 22/32 | 9种常用的数据分析方法
  5. 在 ubuntu下面利用libpcap编程
  6. 删除右键菜单中的选项:在Visual Studio中打开
  7. 文献记录(part95)--CCMS: A nonlinear clustering method based on crowd movement and selection
  8. 虚拟化 VS 容器化(docker)
  9. POJ 2886 Who Gets the Most Candies?
  10. 国二c语言题库 word,国家二级计算机考试MS-Office历年真题题库及答案
  11. java定时任务_定时任务3种实现方式
  12. 61-70作业关系符运算
  13. Hue无法访问HBase Thrift 1 server cannot be contacted: Could not connect to node01:9090
  14. Acwing-4656. 技能升级
  15. 【PS功能学习】04:祖传抠图技法
  16. OpenCV的各种矩阵基本运算、基本操作及示例代码(加、减、乘、点乘、点除、乘方、开方、累加、转置、比较等)
  17. 屏蔽网通域名纠错系统
  18. 《张艺谋这个人》较真
  19. Python |浅谈爬虫的由来
  20. 私人定制YX3系列高效节能电动机:这才是大腕儿!

热门文章

  1. WIN11安装node.js
  2. 英频杰Indy固件手册中文版(二)
  3. 恢复华为手机桌面计算机,如何恢复华为手机桌面
  4. Java字符串反转以及数组集合转换的方法
  5. 敏感性方法matlab的代码,全局敏感性分析工具箱
  6. 用钩子函数实现鼠标动作录制
  7. 手机也能开机启动(值得研究一下啊!在索尼爱立信上面发现的)
  8. vivado CORDIC ip核计算arctan记录
  9. DRM 架构简要说明
  10. c语言怎么计算bmp图像大小,C语言如何取出一张256色位的bmp图像的某个像素的颜色...