zoukankan      html  css  js  c++  java
  • Magic Powder

    http://codeforces.com/problemset/problem/670/D2

    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



    #include <cstdio>
    #include <cstring>
    #include <iostream>
    #include <cmath>
    #include <vector>
    #include <algorithm>
    #include <string>
    #include <map>
    using namespace std;
    
    #define N 110000
    #define met(a, b) memset(a, b, sizeof(a))
    #define INF 0x3f3f3f3f
    const long long  Max = 2000000000;
    typedef long long LL;
    
    
    LL a[N], b[N];
    LL n, k;
    
    LL Judge(LL mid)
    {
        LL i, K1=k, K2=k;
    
        for(i=1; i<=n; i++)
        {
            if(b[i]<a[i]*mid)
            {
                K1 -= (a[i]*mid - b[i]);
                if(K1<0)
                    return -1;
            }
        }
    
        for(i=1; i<=n; i++)
        {
            if(b[i]<a[i]*(mid+1))
            {
                K2 -= (a[i]*(mid+1) - b[i]);
                if(K2<0)
                    return 0;
            }
        }
    
        return 1;
    }
    
    int main()
    {
    
    
        while(scanf("%I64d%I64d", &n, &k)!=EOF)
        {
            LL i;
            LL mid, L=0, R=Max, ans;
    
            met(a, 0);
            met(b, 0);
    
            for(i=1; i<=n; i++)
                scanf("%I64d", &a[i]);
            for(i=1; i<=n; i++)
                scanf("%I64d", &b[i]);
    
            while(L<R)
            {
                mid = (L+R)/2;
                ans = Judge(mid);
                if(ans==0)
                    L = R = mid;
                if(ans>0)
                    L = mid + 1;
                if(ans<0)
                    R = mid - 1;
            }
    
            printf("%I64d
    ", L);
        }
    
        return 0;
    }


  • 相关阅读:
    VM环境安装Linux系统
    设置ShowDialog
    sqlserver同步表的脚本
    C#winform设置DateTimePicker的时间格式
    C#winform解析marc显示在datagridview中以及marc卡片显示
    C#实现图书馆程序导入ISO-2709格式(MARC)功能
    时间格式转换+固定字段加空格
    sqlserver 保留小数方法
    winform的datagridview单元格输入限制和右键单击datagridview单元格焦点跟着改变
    怎么查看那个端口被占用
  • 原文地址:https://www.cnblogs.com/YY56/p/5466361.html
Copyright © 2011-2022 走看看