• 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;
    }
  • 相关阅读:
    根据方法名执行方法的例子
    修改cmd的默认路径
    事件处理程序的处理顺序问题
    类型事件定义
    修改应用程序搜索程序集的私有路径
    What's New in Visual Studio 2010
    IE 8 中选项卡通过颜色分组
    再谈CLR:无法避免的装箱
    环境变量(Environment Variable)那点事
    默认情况下程序启动后到底是几个线程?
  • 原文地址:https://www.cnblogs.com/qscqesze/p/5465788.html
Copyright © 2020-2023  润新知