zoukankan      html  css  js  c++  java
  • Codeforces Round #350 (Div. 2) D1. Magic Powder

    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;
    }
  • 相关阅读:
    基于WebGIS的电子政务应用(基于J2EE的MVC架构)
    和菜鸟一起学c之函数中堆栈及运行内存情况
    《父亲》献给程序员的我们
    黑客高级技巧之Linux后门技术及实践
    批处理实现对网站的监测
    无敌批处理
    Adsutil.vbs在脚本入侵中的妙用
    黑客高级技巧之Linux后门技术及实践
    ms 06014漏洞检测代码
    ms 06014漏洞检测代码
  • 原文地址:https://www.cnblogs.com/qscqesze/p/5465788.html
Copyright © 2011-2022 走看看