题干:

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 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 ningredients 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 the i-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 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.

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 index 1 and 1 gram of magic powder to ingredient with the index 3. 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.

解题报告:

单单从这一道题上来看,先找出不用magic powder所能做的最大蛋糕数,然后模拟多做一个蛋糕,两个蛋糕....一直到magic powder小于等于0为止。但是因为这道题还有后续()所以最好是用枚举去理解,也就是先找出不用magic powder所能做的最大蛋糕数,然后枚举做一个蛋糕,做两个蛋糕,,一直到magic powder小于等于0为止。然后 对于那个后续的题目,就是针对这一枚举的过程用二分优化,来加快查找速度。

AC代码:

#include<bits/stdc++.h>using namespace std;
const int INF = 0x3f3f3f3f;
int a[1005],b[1005];
int main()
{int n,qq;cin>>n>>qq;for(int i = 1; i<=n; i++) scanf("%d",&a[i]);for(int i = 1; i<=n; i++) scanf("%d",&b[i]);int minn = INF;for(int i = 1; i<=n; i++) {minn = min(minn,b[i]/a[i]);}for(int i =1; i<=n; i++) {b[i]-=minn*a[i];}int ans = minn;int flag = 1;while(flag) {for(int i = 1; i<=n; i++) {if(b[i] < a[i]) {qq-=(a[i]-b[i]);if(qq >= 0) b[i] =a[i];}if(qq <= 0) {flag = 0;break;}}for(int i = 1; i<=n; i++) {if(b[i] < a[i]) {ans--;break;}b[i]-=a[i];}ans++;}printf("%d\n",ans);return 0 ;
}

【CodeForces - 670D1 】Magic Powder - 1 (模拟 或 枚举 或二分优化)相关推荐

  1. codeforces 670D1 Magic Powder - 1

    题目链接:http://codeforces.com/problemset/problem/670/D1 题目:Magic Powder - 1 time limit per test 1 secon ...

  2. CodeForces 670D2 Magic Powder - 2

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

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

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

  4. CodeForces 670D Magic Powder

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

  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. CodeForces 1463 C. Busy Robot 模拟

    CodeForces 1463 C. Busy Robot 模拟 题目大意: 有一个一维坐标轴,在最初时刻有个机器人位于坐标 0 0 0 位置,有 n n n 个命令,对于每一个命令在 t i t_i ...

  8. codeforce之Magic Powder

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

  9. Magic Powder - 1,2

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

最新文章

  1. 分布式任务调度系统V1
  2. 准确率precison与正确率accuracy区别
  3. 下一代超大规模软件定义网络技术实践
  4. C 编程异常 — double free or corruption (fasttop)
  5. Spark Streaming事务
  6. ref:ThinkPHP Builder.php SQL注入漏洞(= 3.2.3)
  7. koa2 mysql增删改查_react+koa2+mysql零门槛的全栈体验,附上完整项目分享
  8. spring aop搭建(2) :基于代码的实现
  9. oracle 删除用户和依赖,Oracle 12.2使用手动创建与注册依赖对象来执行联机重定义...
  10. windows10 查看端口占用
  11. js代码前面的分号是什么意思?
  12. Lucas-Kanade稀疏光流法
  13. MySQL菜鸟学习日志——0001
  14. 1118 Birds in Forest (25分)——(并查集)
  15. 除尘器选型需要考虑的因素
  16. ei指什么_今天说一下EI是什么
  17. 操作系统接口之批处理作业
  18. windows10计算机放桌面,将win10计算器放在桌面上的操作方法
  19. h5(网页) 调用相机拍照和相册,实现图片上传功能
  20. tga怎么转成png格式?

热门文章

  1. android mysql sqlite_Android SQLite数据库基本操作方法
  2. android开发app初始化,安卓快速开发框架(一)XBaseAndroid初始化使用
  3. sql如何遍历几百万的表_SQL Server遍历表中记录的2种方法(使用表变量和游标)
  4. 软件测试之黑盒测试-等价类划分法
  5. 递归——阶乘加斐波那契数列(简单掌握递归思想的敲门砖)
  6. 怎么实现hover_web前端CSS实现一个粒子动效的按钮
  7. centos7挂载nas存储_CentOS7搭建NAS文件共享存储
  8. 用python模拟评委打分_用vb 编写一个评委打分的程序1. 编写一个评委打分的程序,实现以下功能:a) 单击“评委给分”按钮时弹出InputBo...
  9. 成都软件工程师python_为什么每个软件工程师都应该学习Python?
  10. 限定概率抽奖_守护星已点亮,内测皮肤得到没?从天美抽奖概率分析:地址什么梗...