Codeforces Round #350 (Div. 2) D1. Magic Powder - 1 二分

时间:2022-08-22 16:35:45

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 二分的更多相关文章

  1. Codeforces Round &num;350 &lpar;Div&period; 2&rpar;&lowbar;D2 - Magic Powder - 2

    D2. Magic Powder - 2 time limit per test 1 second memory limit per test 256 megabytes input standard ...

  2. Codeforces Round &num;350 &lpar;Div&period; 2&rpar; D2&period; Magic Powder - 2

    题目链接: http://codeforces.com/contest/670/problem/D2 题解: 二分答案. #include<iostream> #include<cs ...

  3. Codeforces Round &num;350 &lpar;Div&period; 2&rpar; D1

    D1. Magic Powder - 1 time limit per test 1 second memory limit per test 256 megabytes input standard ...

  4. Codeforces Round &num;365 &lpar;Div&period; 2&rpar; C - Chris and Road 二分找切点

    // Codeforces Round #365 (Div. 2) // C - Chris and Road 二分找切点 // 题意:给你一个凸边行,凸边行有个初始的速度往左走,人有最大速度,可以停 ...

  5. Codeforces Round &num;350 &lpar;Div&period; 2&rpar;A&comma;B&comma;C&comma;D1

    A. Holidays time limit per test 1 second memory limit per test 256 megabytes input standard input ou ...

  6. Codeforces Round &num;350 &lpar;Div&period; 2&rpar; A B C D1 D2 水题【D2 【二分&plus;枚举】好题】

    A. Holidays 题意:一个星球 五天工作,两天休息.给你一个1e6的数字n,问你最少和最多休息几天.思路:我居然写成模拟题QAQ. #include<bits/stdc++.h> ...

  7. Codeforces Round &num;540 &lpar;Div&period; 3&rpar; D1&period; Coffee and Coursework &lpar;Easy version&rpar; 【贪心】

    任意门:http://codeforces.com/contest/1118/problem/D1 D1. Coffee and Coursework (Easy version) time limi ...

  8. Codeforces Round &num;527 &lpar;Div&period; 3&rpar; D1&period; Great Vova Wall &lpar;Version 1&rpar; 【思维】

    传送门:http://codeforces.com/contest/1092/problem/D1 D1. Great Vova Wall (Version 1) time limit per tes ...

  9. Codeforces Round &num;542&lpar;Div&period; 2&rpar; D1&period;Toy Train

    链接:https://codeforces.com/contest/1130/problem/D1 题意: 给n个车站练成圈,给m个糖果,在车站上,要被运往某个位置,每到一个车站只能装一个糖果. 求从 ...

随机推荐

  1. &lbrack;转载&rsqb;TFS源代码管理

    以下主要描述了: TFS源代码控制系统的基本场景 如何把一个项目添加到源代码管理中 如何与服务器同步 如何做Check-In 如何做分支与合并 什么是上架与下架 我们知道工作项是项目管理的基本元素,但 ...

  2. UNIX &sol; Linux&colon; 2 Ways to Add Swap Space Using dd&comma; mkswap and swapon

    UNIX / Linux: 2 Ways to Add Swap Space Using dd, mkswap and swapon by RAMESH NATARAJAN on AUGUST 18, ...

  3. java 编写hadoop程序中使用第三方libxx&period;so库

    在使用java编写hadoop处理程序时遇到了,java使用依赖的第三方libxx.so库的情况,找到了一种可行的方法,记录一下,希望对别人也有帮助: 加入需要使用的lib库为libxxx.so 1. ...

  4. 微软IOC容器Unity简单代码示例3-基于约定的自动注册机制

    @(编程) [TOC] Unity在3.0之后,支持基于约定的自动注册机制Registration By Convention,本文简单介绍如何配置. 1. 通过Nuget下载Unity 版本号如下: ...

  5. YYHS-NOIP模拟赛-gcd

    题解 这道题题解里说用莫比乌斯反演做(我这个蒟蒻怎么会做呢) 但是不会,所以我们另想方法,这里我们用容斥来做 我们先把500000以内的所有质数筛出来 每次读入编号的时候,先把编号对应的这个数分解质因 ...

  6. 浅谈Linux文件与目录权限

    作为一个程序员,在工作的过程中或多或少都会接触都Linux,那么对于权限这块肯定有所了解,今天有空想谈谈觉得比较绕的权限问题,即文件权限与目录权限 1.文件权限,对于文件权限这个是比较简单的,也很容易 ...

  7. vue樣式綁定

    vue的樣式可以使得class,style不僅可以綁定文本,而且可以綁定數組和對象. 使用對象{} 使用數組 綁定對象 使用computed屬性, 使用內聯樣式.

  8. Jmeter-使用Stepping Thread Group插件来设置负载场景

    前言: 什么是实际的性能测试???1)思考时间:用户在做不同操作之间有时间停顿,或者延迟,思考时间就是模拟用户的操作过程中的停顿的间.2)步伐,速度:主要包括,大量用户进来的时间和退出时间,控制迭代之 ...

  9. textarea标签内的文字无缘故居中解决原因

    <textarea> 内容内容 </textarea> 浏览器会解析为 <textarea><br>     内容内容</textarea> ...

  10. &lbrack;Codeforces Round &num;492 &lpar;Div&period; 1&rpar; &rsqb;&lbrack;B&period; Suit and Tie&rsqb;

    http://codeforces.com/problemset/problem/995/B 题目大意:给一个长度为2*n的序列,分别有2个1,2,3,...n,相邻的位置可以进行交换,求使所有相同的 ...