zoukankan      html  css  js  c++  java
  • codeforces 350 div2 D Magic Powder

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

    The term of this problem is the same as the previous one, the only exception — increased restrictions.

    Input

    The first line contains two positive integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ 109) — the number of ingredients and the number of grams of the magic powder.

    The second line contains the sequence a1, a2, ..., an (1 ≤ ai ≤ 109), 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 ≤ 109), 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.

    Examples
    input
    1 1000000000
    1
    1000000000
    output
    2000000000
    input
    10 1
    1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000
    1 1 1 1 1 1 1 1 1 1
    output
    0
    input
    3 1
    2 1 4
    11 3 16
    output
    4
    input
    4 3
    4 3 5 6
    11 12 14 20
    output
    3
    思路:直接二分查找最大能制造的饼干数,把上界设的2*10^9+1;最后你可能相差1,判断一下;
       (d-1直接暴力模拟就好了)
    #include<iostream>
    #include<cstdio>
    #include<cmath>
    #include<string>
    #include<queue>
    #include<algorithm>
    #include<stack>
    #include<cstring>
    #include<vector>
    #include<list>
    #include<set>
    #include<map>
    using namespace std;
    #define ll __int64
    #define mod 1000000007
    #define inf 999999999
    //#pragma comment(linker, "/STACK:102400000,102400000")
    int scan()
    {
        int res = 0 , ch ;
        while( !( ( ch = getchar() ) >= '0' && ch <= '9' ) )
        {
            if( ch == EOF ) return 1 << 30 ;
        }
        res = ch - '0' ;
        while( ( ch = getchar() ) >= '0' && ch <= '9' )
            res = res * 10 + ( ch - '0' ) ;
        return res ;
    }
    ll a[100010];
    ll b[100010];
    ll check(ll x,ll gg,ll y)
    {
        ll cha=0;
        for(ll i=1;i<=x;i++)
        {
            if(a[i]*gg>b[i])
            cha+=a[i]*gg-b[i];
            if(cha>y)
            return 0;
        }
        return 1;
    }
    int main()
    {
        ll x,y,z,i,t;
        scanf("%I64d%I64d",&x,&y);
        for(i=1;i<=x;i++)
        scanf("%I64d",&a[i]);
        for(i=1;i<=x;i++)
        scanf("%I64d",&b[i]);
        ll st=0;
        ll en=2000000000;
        while(st<en)
        {
            ll mid=(st+en)>>1;
            if(check(x,mid,y))
            st=mid+1;
            else
            en=mid;
        }
        if(check(x,st,y))
        printf("%I64d
    ",st);
        else
        printf("%I64d
    ",st-1);
        return 0;
    }
    View Code
  • 相关阅读:
    MySQL-07-新增数据
    MySQL-06-表结构修改
    LVM-创建与增容
    Zabbix-4.0.34-安装配置
    MySQL-05-约束
    lnmp(部署在一台上面)
    shell脚本概念和yum仓库的搭建
    awk命令基础和进阶
    shell
    awk
  • 原文地址:https://www.cnblogs.com/jhz033/p/5465379.html
Copyright © 2011-2022 走看看