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;
    }
  • 相关阅读:
    css3 rotate(1turn)的用法
    canvas svg webgl threejs d3js 的区别
    利用css3给座右铭设置漂亮的渐变色
    svg相关的知识
    Mark标记功能的实现(像手工标记的一样)
    终于搞清楚了正向代理与反向代理的区别
    获取免费ip_存入excel_用了线程池_封装清晰
    爬去京东——智能音箱
    滑动验证码
    天气爬取的笔记
  • 原文地址:https://www.cnblogs.com/qscqesze/p/5465788.html
Copyright © 2011-2022 走看看