Codeforces Round #350 (Div. 2) D1. Magic Powder - 1 二分
D1. Magic Powder - 1
题目连接:
http://www.codeforces.com/contest/670/problem/D1
Description
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 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 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.
Sample Input
3 1
2 1 4
11 3 16
Sample Output
4
题意
你的蛋糕需要n个原材料,你现在有k个魔法材料,魔法材料可以转化为任何材料
现在告诉你蛋糕每个材料需要多少,以及你现在有多少个
问你最多能够做出多少个蛋糕来
题解:
直接二分就好了,注意加起来会爆int
以及r给到2e9才行
代码
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+7;
long long a[maxn],b[maxn],k;
int n;
bool check(long long x)
{
long long ans = 0;
for(int i=1;i<=n;i++)
if(a[i]*x-b[i]>k)return false;
for(int i=1;i<=n;i++)
ans+=max(a[i]*x-b[i],0LL);
if(ans<=k)return true;
return false;
}
int main()
{
scanf("%d%lld",&n,&k);
for(int i=1;i<=n;i++)scanf("%lld",&a[i]);
for(int i=1;i<=n;i++)scanf("%lld",&b[i]);
long long l=0,r=2e9,ans=0;
while(l<=r)
{
int mid=(l+r)/2;
if(check(mid))l=mid+1,ans=mid;
else r=mid-1;
}
cout<<ans<<endl;
}
Codeforces Round #350 (Div. 2) D1. Magic Powder - 1 二分的更多相关文章
- Codeforces Round #350 (Div. 2)_D2 - Magic Powder - 2
D2. Magic Powder - 2 time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces Round #350 (Div. 2) D2. Magic Powder - 2
题目链接: http://codeforces.com/contest/670/problem/D2 题解: 二分答案. #include<iostream> #include<cs ...
- Codeforces Round #350 (Div. 2) D1
D1. Magic Powder - 1 time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces Round #365 (Div. 2) C - Chris and Road 二分找切点
// Codeforces Round #365 (Div. 2) // C - Chris and Road 二分找切点 // 题意:给你一个凸边行,凸边行有个初始的速度往左走,人有最大速度,可以停 ...
- Codeforces Round #350 (Div. 2)A,B,C,D1
A. Holidays time limit per test 1 second memory limit per test 256 megabytes input standard input ou ...
- Codeforces Round #350 (Div. 2) A B C D1 D2 水题【D2 【二分+枚举】好题】
A. Holidays 题意:一个星球 五天工作,两天休息.给你一个1e6的数字n,问你最少和最多休息几天.思路:我居然写成模拟题QAQ. #include<bits/stdc++.h> ...
- Codeforces Round #540 (Div. 3) D1. Coffee and Coursework (Easy version) 【贪心】
任意门:http://codeforces.com/contest/1118/problem/D1 D1. Coffee and Coursework (Easy version) time limi ...
- Codeforces Round #527 (Div. 3) D1. Great Vova Wall (Version 1) 【思维】
传送门:http://codeforces.com/contest/1092/problem/D1 D1. Great Vova Wall (Version 1) time limit per tes ...
- Codeforces Round #542(Div. 2) D1.Toy Train
链接:https://codeforces.com/contest/1130/problem/D1 题意: 给n个车站练成圈,给m个糖果,在车站上,要被运往某个位置,每到一个车站只能装一个糖果. 求从 ...
随机推荐
- souce insight出错 There was an error opening project
souce insight出错 There was an error opening project: "...": Options->Preferences->Fol ...
- 如何提高单片机Flash的擦写次数
所谓提高flash的擦写次数,并不是真正的提高flash擦写次数,而是通过以"空间换时间"概念,在软件上实现“操作的次数大于其寿命”.详见链接: http://bbs.eeworl ...
- java基础78 Servlet的生命周期
1.Servlet的生命周期 简单的解析就是: 创建servlet实例(调用构造器)---->调用init()方法---->调用service()方法----->调用destroy( ...
- 《Javascript启示录》要点汇总
前言:本文是阅读<Javascript启示录>后的一个读书笔记,对本书的要点进行了一个归纳,不是原创内容哦.要想详细了解相关内容,请阅读原书. 对象是由存储值的已命名属性组成的. Java ...
- WiFi无线连接真机进行Appium自动化测试方法
有时需要测试APP 产品的耗电问题,但用自动化又面临了一个USB接电脑供电的问题,从而导致计算出来的功耗与手动跑,存在有很大的误差,因此可使用wifi无线连接到手机进行自动化测试,解决功耗问题. 前提 ...
- TCP连接建立与断开
tcp状态 LISTEN:侦听来自远方的TCP端口的连接请求 LISTEN:侦听来自远方的TCP端口的连接请求 SYN-SENT:再发送连接请求后等待匹配的连接请求 SYN-RECEIVED:再收到和 ...
- 静态链接库(lib)、动态链接库(dll)与动态链接库的导入库(lib)
静态链接库与动态链接库相对应.动态链接库的导入库不同于以上两种库. 1.静态链接库(lib) 程序编译一般需经编辑.编译.连接.加载和运行几个步骤.在我们的应用中,有一些公共代码是需要反复使用 ...
- 【BZOJ】4671: 异或图
题解 写完之后开始TTTTTTT--懵逼 这道题我们考虑一个东西叫容斥系数啊>< 这个是什么东西呢 也就是\(\sum_{i = 1}^{m}\binom{m}{i}f_{i} = [m ...
- python之web框架(3):WSGI之web应用完善
python之web框架(3):WSGI之web应用完善 1.上篇的web框架太low,只能实现回应固定页面.现在将它进行完善.首先将wsgi和web服务器进行分离,并给予它回复静态页面的能力. we ...
- Asp.Net Core2.0允许跨域请求设置
1.services /// <summary> /// /// </summary> /// <param name="services">& ...