• Codeforces Round #350 (Div. 2) D2. Magic Powder


    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
    

     

    题目的大致意思是有k克的魔法面粉,可以变成任意一种面粉。要做一个饼干,需要n中面粉。第二行是做一个饼干所需要的第i种面粉的量。第三行是第i种面粉的含量。求最多能做多少个饼干。

    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    using namespace std;
    
    long long n, k, a[100010], b[100010];
    bool judge(long long x) {
        long long res = k;
        for (long long i = 0; i < n; i++) {
            if (x > b[i]/a[i] ) {
                if (res < a[i]*x - b[i]) return false;
                else res -= a[i]*x - b[i];
            }
        }
        return true;
    }
    int main() {
        while (scanf("%lld%lld", &n, &k) != EOF) {
            for (long long i = 0; i < n; i++) {
                scanf("%lld", &a[i]);
            }
            for (long long j = 0; j < n; j++) {
                scanf("%lld", &b[j]);
            }
            long long lb = 0, ub = 2e9 + 10;
            long long ans = 0;
            while (ub >= lb) {
                long long mid = (lb + ub)/2;
                if (judge(mid)) {
                    ans = mid;
                    lb = mid + 1;
                }
                else ub = mid - 1;
            }
            printf("%lld
    ", ans);
        }
        return 0;
    }
  • 相关阅读:
    MySQL 的连接时长控制--interactive_timeout和wait_timeout
    查看MySQL 连接信息--连接空闲时间及正在执行的SQL
    mysql timestamp为0值时,python读取后的对象为None
    MySQL基础普及《MySQL管理之道:性能调优、高可用与监控》
    读《大秦帝国》第三部
    golang mysql 如何设置最大连接数和最大空闲连接数
    如何查看MySQL connection id连接id
    JAVA配置环境变量
    PB常见功能实现代码
    PB中数据窗口自动换行
  • 原文地址:https://www.cnblogs.com/cniwoq/p/6770909.html
Copyright © 2020-2023  润新知