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

题干:

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 ;
}

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/441767.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

第二课计算机ppt,第二课计算机系统.ppt

第二课计算机系统主要部件功能及参数指标 机 箱 外 壳 一个完整的计算机系统是由硬件(Hardware)系统和软件(Software)系统两大部分组成。 计算机硬件是指系统中可触摸得到的设备实体&#xff0c;是计算机工作的基础。 计算机软件是指在硬件设备上运行的各种程序和文档。 软件系…

正则表达式 python_Python正则表达式总结

之前我们讲解了 正则表达式 的起源、发展、流派、语法、引擎、优化等相关知识&#xff0c;今天我们主要来学习一下 正则表达式在 Python语言 中的应用&#xff01;大多数编程语言的正则表达式设计都师从Perl&#xff0c;所以语法基本相似&#xff0c;不同的是每种语言都有自己的…

建立远程ftp服务器,利用无线路由器建立FTP服务器

路由器的应用非常广泛&#xff0c;无线路由器技术也更加的完善和稳定&#xff0c;利用无线路由器能构建FTP服务器。下面&#xff0c;我就具体的方法在这里拿出来和大家分享一下&#xff0c;希望对大家有用。一、FTPFTP(文件传输协议)诞生之后&#xff0c;便迅速地得到了推广和应…

【HDU - 5912】Fraction (模拟)

题干&#xff1a; Mr. Frog recently studied how to add two fractions up, and he came up with an evil idea to trouble you by asking you to calculate the result of the formula below: As a talent, can you figure out the answer correctly? Input The first …

vue mysql webapp_基于Laravel+VueJS实战开发WebAPP

资源介绍【课程内容】1-git库与开发环境及工具软件介绍2-安装laravel框架3-安装laravel-ide-helper增强代码提示4-配置数据库与使用migrations创建表5-解决mysql5.7以下laravel不能执行数据迁移的问题6-合理的路由布局与分组路由7-远程开发环境服务器搭建与虚拟面板的使用8-使用…

计算机测试怎么提交,Win7电脑怎么测试上传速度?

做网站的人都知道上传速度是很重要的&#xff0c;因为太差的上传速度会影响工作的进度&#xff0c;所以他们经常要对上传速度进行测试&#xff0c;但是有一些新手不知道Win7电脑怎么测试上传速度&#xff1f;为此小编赶紧整理了以下教程&#xff0c;不知道的朋友赶紧来看看吧&a…

【HDU - 5914 】Triangle (打表 或 set维护)

题干&#xff1a; Mr. Frog has n sticks, whose lengths are 1,2, 3⋯⋯n respectively. Wallice is a bad man, so he does not want Mr. Frog to form a triangle with three of the sticks here. He decides to steal some sticks! Output the minimal number of sticks h…

harmonyos消息服务器,第三方纯HarmonyOS应用太少,你还愿意升级吗?

部分纯鸿蒙 HarmonyOS 应用已上线&#xff1a;图标多了“HMOS”角标标识&#xff0c;而只有真正的鸿蒙系统应用才能真正体验到万能卡片等系列的功能&#xff0c;但是很明显目前真正属于鸿蒙系统的第三方应用太少……基本上都是华为自身的应用&#xff0c;那么如果应用太少你还愿…

如何释放mysql连接资源_CI框架出现mysql数据库连接资源无法释放的解决方法

本文实例分析了CI框架出现mysql数据库连接资源无法释放的解决方法。分享给大家供大家参考&#xff0c;具体如下&#xff1a;使用ci框架提供的类查询数据&#xff1a; $this->load->database();$query $this->db->query($sql);程序运行一段时间之后&#xff0c;报错…

【nyoj - 860】 又见0-1背包 (dp,反向0-1背包,好题好思路)

题干&#xff1a; 又见01背包 时间限制&#xff1a;1000 ms | 内存限制&#xff1a;65535 KB 难度&#xff1a;3 输入 多组测试数据。 每组测试数据第一行输入&#xff0c;n 和 W &#xff0c;接下来有n行&#xff0c;每行输入两个数&#xff0c;代表第i个物品的wi 和 v…

300英雄服务器维护多久,《300英雄》2021年5月20日6:00-9:00更新维护公告

尊敬的《300英雄》玩家:《300英雄》将于2021年5月20日6:00-9:00(星期四)&#xff0c;对所有大区进行停机更新&#xff0c;更新期间&#xff0c;您将无法登录游戏。如果在预定时间内无法完成维护内容&#xff0c;开服时间也将继续顺延。具体更新内容如下&#xff1a;一、活动相关…

c 连接mysql示例 源码_MySQL 连接

MySQL 连接使用mysql二进制方式连接您可以使用MySQL二进制方式进入到mysql命令提示符下来连接MySQL数据库。实例以下是从命令行中连接mysql服务器的简单实例&#xff1a;[[email protected]]# mysql -u root -pEnter password:******在登录成功后会出现 mysql> 命令提示窗口…

【 FZU - 2214 】Knapsack problem(逆向0-1背包)

题干&#xff1a; Given a set of n items, each with a weight w[i] and a value v[i], determine a way to choose the items into a knapsack so that the total weight is less than or equal to a given limit B and the total value is as large as possible. Find the …

服务器2008系统如何设置休眠时间,Win7休眠和睡眠怎么开启(Win2008)

如果把 Win7休眠和睡眠关闭了&#xff0c;需要的时候可以用命令重新开启&#xff0c;毕竟这两个功能不但可以节约电&#xff0c;还可以迅速恢复工作状态&#xff0c;节约开机开软件的时间。Win2008 R2 跟 Win7 同一内核&#xff0c;开启休眠和睡眠的命令也一样。在开启休眠和睡…

【HDU - 1220】Cube (组合数学,简单)

题干&#xff1a; Cowl is good at solving math problems. One day a friend asked him such a question: You are given a cube whose edge length is N, it is cut by the planes that was paralleled to its side planes into N * N * N unit cubes. Two unit cubes may h…

java poi读取word中附件_Java POI导入word, 带图片

1.导入文件示例&#xff0c;word中简历表格模板2.代码示例分两部分&#xff0c;一部分读取图片/*** 导入word(基本信息&#xff0c;word格式)* param staffId* param baseInfoFile*/void importStaffInfo(Integer staffId, MultipartFile file);-- 读取图片InputStream inputSt…

如何将文件拷贝服务器上,如何将文件复制到云服务器上

如何将文件复制到云服务器上 内容精选换一换将文件上传至Windows云服务器一般会采用MSTSC远程桌面连接的方式。本节为您介绍本地Windows计算机通过远程桌面连接&#xff0c;上传文件至Windows云服务器的操作方法。Windows云服务器可以访问公网。在本地Windows计算机上&#xff…

mysql5.7解压版错误_mysql 5.7 解压版 安装net start mysql 发生系统错误 2

1.配置环境变量 用户变量path 添加 mysql 安装目录2.新建my.ini文件 放到E:\mysql-5.7.24-winx64安装目录下[mysqld]port 3306basedirC:/software/mysql-5.7.21-winx64datadirC:/software/mysql-5.7.21-winx64/datamax_connections200character-set-serverutf8default-storage…

【HDU - 2553】N皇后问题 (dfs经典问题,回溯,搜索)

题干&#xff1a; 在N*N的方格棋盘放置了N个皇后&#xff0c;使得它们不相互攻击&#xff08;即任意2个皇后不允许处在同一排&#xff0c;同一列&#xff0c;也不允许处在与棋盘边框成45角的斜线上。 你的任务是&#xff0c;对于给定的N&#xff0c;求出有多少种合法的放置方…

浪潮服务器建立虚拟驱动器,像《十二时辰》一样去建立标准! 浪潮这款服务器做到了...

原标题&#xff1a;像《十二时辰》一样去建立标准&#xff01; 浪潮这款服务器做到了这个夏天&#xff0c;《长安十二时辰》制霸屏幕开画至今豆瓣评分达到8.8分现已成功“出海”在Amazon、Youtube、Viki付费上线成为唐风古韵的又一风向标现如今&#xff0c;越洋的标准可不止悠悠…