【CodeForce 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 n potions.

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 n, m, k (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.

Examples

Input

20 3 2
10 99
2 4 3
20 10 40
4 15
10 80

Output

20

Input

20 3 2
10 99
2 4 3
200 100 400
4 15
100 800

Output

200

Note

In the first sample, the optimum answer is to use the second spell of the first type that costs 10 manapoints. Thus, the preparation time of each potion changes to 4 seconds. Also, Anton should use the second spell of the second type to instantly prepare 15 potions spending 80 manapoints. The total number of manapoints used is 10 + 80 = 90, and the preparation time is 4·5 = 20 seconds (15 potions were prepared instantly, and the remaining 5 will take 4 seconds each).

In the second sample, Anton can’t use any of the spells, so he just prepares 20 potions, spending 10 seconds on each of them and the answer is 20·10 = 200.

题目描述

Anton玩一个非常interesting的游戏,可是他还差n个potions就可以到达人生巅峰了,如果不使用spells(奇淫巧技),那么Anton每x秒就会产出1个potions,现在给你两种Spells,第一种可以将生产1Potions的时间变为ai,消耗的能力值为bi;第二种将话费di能量直接产生ci的Potions,每种Speels至多使用一次,能量的上限值为s,现在问你Anton升到下一级所要花的最短时间。(施展奇淫巧技不需要时间)

思路

因为第二种Spells产生的Potions值和消耗的能量值是不减的,也就是说消耗的能力值越多威力越大,所以枚举第一种Spells,二分第二种Spells,最终的最小花费时间取最小值即可。

代码

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
typedef long long LL;

using namespace std;
const int maxn=1e9+7;

struct proc
{
    LL v,c;
}a[200000+5],b[200000+5];

int cmp(proc a,proc b)
{
    return a.c<b.c;
}


int main()
{
    LL n,m,k,x,s;
    while(~scanf("%lld %lld %lld",&n,&m,&k))
    {
        scanf("%lld %lld",&x,&s);
        LL ans=n*x;
        a[0].v=x;
        a[0].c=0;
        for(int i=1;i<=m;i++)
        {
            scanf("%lld",&a[i].v);
        }
        for(int i=1;i<=m;i++)
        {
            scanf("%lld",&a[i].c);
        }
        for(int i=1;i<=k;i++)
        {
            scanf("%lld",&b[i].v);
        }
        for(int i=1;i<=k;i++)
        {
            scanf("%lld",&b[i].c);
        }
        sort(a+1,a+1+m,cmp);
        for(int i=0;i<=m;i++)
        {
            if(a[i].c>s) break;
            int lest=s-a[i].c;
            int l=1,r=k;
            LL maxx=0;
            while(l<=r)
            {
                int mid=(l+r)/2;
                if(b[mid].c<=lest)
                {
                    maxx=max(maxx,b[mid].v);
                    l=mid+1;
                }
                else r=mid-1;
            }
            if(n-maxx<=0) ans=0;
            else ans=min(ans,(LL)(n-maxx)*a[i].v); 
        }
        printf("%lld\n",ans);
    }
    return 0;
}
<think>好的,我现在需要帮助用户制定在Codeforces上达到1200分的策略和技巧。首先,用户之前已经询问过类似的问题,所以我得确保回答的结构清晰,并且包含实用的建议。根据系统指令,我需要用中文回答,正确使用LaTeX格式,还要生成相关问题。 首先,用户的目标是达到1200分,这属于入门到中级的过渡阶段。通常,这个分段的问题集中在Div.2的A、B题,有时可能涉及C题。因此,我需要强调基础算法和数据结构的掌握,比如贪心、模拟、排序、二分查找等。 接下来,用户可能需要具体的学习方法,比如刷题策略。这里可以推荐Codeforces的特定题库,比如按照评分筛选题目,从800-1200分的题目开始练习。同时,参加虚拟比赛和定期训练也是关键点。 另外,比赛技巧也很重要,比如快速读题、时间管理、避免罚时等。需要提醒用户注意这些细节,比如先解决简单题,不要卡在难题上。 代码实现方面,用户可能需要优化模板,比如快速输入输出,这在C++中常见,但用户可能使用Python,所以可以建议使用sys.stdin.readline来加速输入。 然后,我需要考虑用户可能的薄弱环节,比如数学基础或者特定算法,比如数论中的模运算、质数判断,或者动态规划的基础问题。这部分需要简要提及,并给出例子,比如如何高效判断质数,或者斐波那契数列的动态规划解法。 最后,生成相关问题时要围绕用户可能进一步需要的内容,比如如何突破瓶颈、特定算法的学习资源、时间管理技巧等。确保问题有针对性,能够引导用户深入下一步的学习。 检查一下是否需要引用,根据示例中的引用,可能不需要添加,但如果有必要可以加入相关资源推荐。同时,确保所有数学表达式用$...$格式,例如时间复杂度O(n log n)可以写成$O(n \log n)$,独立公式用$$...$$,比如动态规划的递推式。 现在组织内容,确保每个部分有清晰的标题,策略分点,代码示例正确,并且语言简洁。可能还需要提醒用户注意题目分类和总结错误,这些都是提高的关键。</think># Codeforces 达到 1200 分的策略与技巧 ## 一、基础能力强化 1. **算法优先级** 重点掌握:贪心、模拟、排序、二分查找、简单动态规划(如背包问题)、基础数论(模运算、质数判断)。 例如二分模板需熟练写出: ```python def binary_search(arr, target): left, right = 0, len(arr)-1 while left <= right: mid = (left + right) // 2 if arr[mid] < target: left = mid + 1 else: right = mid - 1 return left ``` 2. **时间复杂度控制** - 数据规模 ≤ $10^3$:允许 $O(n^2)$ 算法 - 数据规模 ≤ $10^5$:必须使用 $O(n \log n)$ 或更低复杂度 ## 二、针对性训练方法 1. **题目选择策略** - 使用Codeforces题库过滤器:`Difficulty: 800-1200` - 按标签分类训练:每周专注1-2个算法类型 2. **虚拟参赛实践** - 每周至少2场虚拟比赛(推荐Div.2) - 赛后分析:使用Codeforces的`PRACTICE`功能重做未通过题目 ## 三、比赛实战技巧 1. **解题顺序优化** - 开赛前5分钟快速浏览所有题目 - 建议顺序:A → B → D → C(根据实际难度动态调整) 2. **代码模板预置** 准备常用代码片段加速编写: ```python import sys from collections import defaultdict def main(): input = sys.stdin.readline n = int(input()) arr = list(map(int, input().split())) # 解题代码 if __name__ == "__main__": main() ``` ## 四、关键数学模型 1. **数论基础** - 快速幂算法:计算 $a^b \mod m$ 时使用 $$a^b \mod m = \begin{cases} 1 & b=0 \\ (a^{b/2})^2 \mod m & b \text{为偶数} \\ a \cdot (a^{(b-1)/2})^2 \mod m & b \text{为奇数} \end{cases}$$ 2. **动态规划模型** 经典斐波那契数列DP实现: ```python def fib(n): dp = [0] * (n+1) dp[1] = 1 for i in range(2, n+1): dp[i] = dp[i-1] + dp[i-2] return dp[n] ``` ## 五、效率提升工具 1. **调试技巧** - 边界测试:n=0/1, 数组全相同元素等极端情况 - 使用Python的`pdb`模块进行断点调试 2. **资源推荐** - [Errichto的算法教学频道](https://www.youtube.com/c/Errichto)(适合可视化学习) - Codeforces EDU板块的《Binary Search》课程[^1]
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值