zoukankan      html  css  js  c++  java
  • 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;
    }
  • 相关阅读:
    logstash 1.5.3 配置使用redis做续传
    buildbot的codebaseGenerator
    java 进程启用远程查看
    ubuntu Server 14 自动更新
    【转载】Securing Kibana + Elasticsearch
    U盘安装ubuntu server 12.04的问题检测不到CDROM的解决
    elasticsearch auto delete old indices
    elastic search 配置问题
    logstash 因为jdk版本不对造成索引时间戳失败
    ELK stack elasticsearch/logstash/kibana 关系和介绍
  • 原文地址:https://www.cnblogs.com/cniwoq/p/6770909.html
Copyright © 2011-2022 走看看