zoukankan      html  css  js  c++  java
  • Codeforces 734C. Anton and Making Potions(二分)

    Anton is playing a very interesting computer game, but now he is stuck at one of the levels. To pass to the next level he has to prepare npotions.

    Anton has a special kettle, that can prepare one potions in x seconds. Also, he knows spells of two types that can faster the process of preparing potions.

    1. Spells of this type speed up the preparation time of one potion. There are m spells of this type, the i-th of them costs bi manapoints and changes the preparation time of each potion to ai instead of x
    2. Spells of this type immediately prepare some number of potions. There are k such spells, the i-th of them costs di manapoints and instantly create ci potions. 

    Anton can use no more than one spell of the first type and no more than one spell of the second type, and the total number of manapoints spent should not exceed s. Consider that all spells are used instantly and right before Anton starts to prepare potions.

    Anton wants to get to the next level as fast as possible, so he is interested in the minimum number of time he needs to spent in order to prepare at least n potions.

    Input

    The first line of the input contains three integers nmk (1 ≤ n ≤ 2·109, 1 ≤ m, k ≤ 2·105) — the number of potions, Anton has to make, the number of spells of the first type and the number of spells of the second type.

    The second line of the input contains two integers x and s (2 ≤ x ≤ 2·109, 1 ≤ s ≤ 2·109) — the initial number of seconds required to prepare one potion and the number of manapoints Anton can use.

    The third line contains m integers ai (1 ≤ ai < x) — the number of seconds it will take to prepare one potion if the i-th spell of the first type is used.

    The fourth line contains m integers bi (1 ≤ bi ≤ 2·109) — the number of manapoints to use the i-th spell of the first type.

    There are k integers ci (1 ≤ ci ≤ n) in the fifth line — the number of potions that will be immediately created if the i-th spell of the second type is used. It's guaranteed that ci are not decreasing, i.e. ci ≤ cj if i < j.

    The sixth line contains k integers di (1 ≤ di ≤ 2·109) — the number of manapoints required to use the i-th spell of the second type. It's guaranteed that di are not decreasing, i.e. di ≤ dj if i < j.

    Output

    Print one integer — the minimum time one has to spent in order to prepare n potions.

    题意:要求得到至少n个药剂,可以使用两种魔法,一种能够缩短制药时间,一种能瞬间制药,

    给你x表示标准制药一个要x秒,给你s表示你的法力值为s

    m种第一类类魔法,消耗b点魔法,缩短时间为a秒。

    k种第二类魔法,消耗d点魔法,瞬间做出c个药。

    两种魔法最多各选一个用,问你最少花多少时间能制得至少n个药剂

    由于题目给出的c,d是递增的,所以这题相对比较简单,只要遍历一遍第一类魔法再二分查找一下最大且和不超过s的第二类魔法这样就能确保

    找到的是最优解,有点贪心的思想。还有一点要注意的,最优的选择可以不用魔法,或者只用一种魔法,这个要注意一下的。

    #include <iostream>
    #include <cstring>
    #include <string>
    #include <algorithm>
    #include <cstdio>
    using namespace std;
    typedef long long ll;
    const int M = 2e5 + 20;
    ll a[M] , b[M] , c[M] , d[M];
    int main()
    {
        ll n , m , k;
        scanf("%I64d%I64d%I64d" , &n , &m , &k);
        ll x , s;
        scanf("%I64d%I64d" , &x , &s);
        for(int i = 0 ; i < m ; i++) {
            scanf("%I64d" , &a[i]);
        }
        for(int i = 0 ; i < m ; i++) {
            scanf("%I64d" , &b[i]);
        }
        for(int i = 0 ; i < k ; i++) {
            scanf("%I64d" , &c[i]);
        }
        for(int i = 0 ; i < k ; i++) {
            scanf("%I64d" , &d[i]);
        }
        ll MIN = n * x;
        a[m] = x;
        for(int i = 0 ; i <= m ; i++) {
            if(s >= b[i]) {
                ll temp = s - b[i];
                int pos = upper_bound(d , d + k , temp) - d;
                if(pos == 0) {
                    MIN = min(MIN , n * a[i]);
                    continue;
                }
                pos--;
                ll gg = n - c[pos];
                gg *= a[i];
                MIN = min(MIN , gg);
            }
        }
        printf("%I64d
    " , MIN);
        return 0;
    }
    
  • 相关阅读:
    OpenYurt v0.4.0 新特性发布:高效地管理边缘存储资源
    OpenKruise v0.9.0 版本发布:新增 Pod 重启、删除防护等重磅功能
    dubbo-go v3 版本 go module 踩坑记
    阿里云携手 VMware 共建云原生 IoT 生态,聚开源社区合力打造领域标准
    一文告诉你Java日期时间API到底有多烂
    LocalDateTime、OffsetDateTime、ZonedDateTime互转,这一篇绝对喂饱你
    全球城市ZoneId和UTC时间偏移量的最全对照表
    全网最全!彻底弄透Java处理GMT/UTC日期时间
    GMT UTC CST ISO 夏令时 时间戳,都是些什么鬼?
    如何保证Redis高可用和高并发
  • 原文地址:https://www.cnblogs.com/TnT2333333/p/6068034.html
Copyright © 2011-2022 走看看