D. Road to Post Office
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Vasiliy has a car and he wants to get from home to the post office. The distance which he needs to pass equals to d kilometers.

Vasiliy's car is not new — it breaks after driven every k kilometers and Vasiliy needs t seconds to repair it. After repairing his car Vasiliy can drive again (but after k kilometers it will break again, and so on). In the beginning of the trip the car is just from repair station.

To drive one kilometer on car Vasiliy spends a seconds, to walk one kilometer on foot he needs b seconds (a < b).

Your task is to find minimal time after which Vasiliy will be able to reach the post office. Consider that in every moment of time Vasiliy can left his car and start to go on foot.

Input

The first line contains 5 positive integers d, k, a, b, t (1 ≤ d ≤ 1012; 1 ≤ k, a, b, t ≤ 106; a < b), where:

  • d — the distance from home to the post office;
  • k — the distance, which car is able to drive before breaking;
  • a — the time, which Vasiliy spends to drive 1 kilometer on his car;
  • b — the time, which Vasiliy spends to walk 1 kilometer on foot;
  • t — the time, which Vasiliy spends to repair his car.
Output

Print the minimal time after which Vasiliy will be able to reach the post office.

Examples
input
5 2 1 4 10
output
14
input
5 2 1 4 5
output
13
Note

In the first example Vasiliy needs to drive the first 2 kilometers on the car (in 2 seconds) and then to walk on foot 3 kilometers (in 12 seconds). So the answer equals to 14 seconds.

In the second example Vasiliy needs to drive the first 2 kilometers on the car (in 2 seconds), then repair his car (in 5 seconds) and drive 2 kilometers more on the car (in 2 seconds). After that he needs to walk on foot 1 kilometer (in 4 seconds). So the answer equals to 13 seconds.

题意:

一个人 有一辆鸡公车,开k千米,会坏,然后需要t秒来修,然后车走1千米耗时为a秒,人走1千米耗时为b秒,问走d千米,最少耗时多少

题解:

这题直接分类讨论,模拟一下就行,不知道为什么在D题这个位置。

详细看代码

 #include<bits/stdc++.h>
#define F(i,a,b) for(int i=a;i<=b;++i)
using namespace std;
typedef long long ll; int main(){
ll d,k,a,b,t,ans=;
scanf("%I64d%I64d%I64d%I64d%I64d",&d,&k,&a,&b,&t);
if(d<=k){printf("%I64d\n",d*a);return ;}
d-=k,ans+=k*a;
if(d<=k){
ll tpa=d*a+t;
ll tpb=d*b;
if(tpa<tpb)ans+=tpa;
else ans+=tpb;
printf("%I64d\n",ans);
return ;
}
ll tpa=k*a+t,tpb=k*b;
if(tpa<tpb){
ll now=d/k;
ans+=tpa*now;
d%=k;
if(d==){printf("%I64d\n",ans);return ;}
}else{
ans+=d*b;
printf("%I64d\n",ans);
return ;
}
tpa=d*a+t;
tpb=d*b;
if(tpa<tpb)ans+=tpa;else ans+=tpb;
printf("%I64d\n",ans);
return ;
}

Educational Codeforces Round 15_D. Road to Post Office的更多相关文章

  1. Educational Codeforces Round 15 Road to Post Office

    Road to Post Office 题意: 一个人要从0走到d,可以坐车走k米,之后车就会坏,你可以修或不修,修要花t时间,坐车单位距离花费a时间,走路单位距离花费b时间,问到d的最短时间. 题解 ...

  2. [Educational Codeforces Round 16]E. Generate a String

    [Educational Codeforces Round 16]E. Generate a String 试题描述 zscoder wants to generate an input file f ...

  3. [Educational Codeforces Round 16]D. Two Arithmetic Progressions

    [Educational Codeforces Round 16]D. Two Arithmetic Progressions 试题描述 You are given two arithmetic pr ...

  4. [Educational Codeforces Round 16]C. Magic Odd Square

    [Educational Codeforces Round 16]C. Magic Odd Square 试题描述 Find an n × n matrix with different number ...

  5. [Educational Codeforces Round 16]B. Optimal Point on a Line

    [Educational Codeforces Round 16]B. Optimal Point on a Line 试题描述 You are given n points on a line wi ...

  6. [Educational Codeforces Round 16]A. King Moves

    [Educational Codeforces Round 16]A. King Moves 试题描述 The only king stands on the standard chess board ...

  7. Educational Codeforces Round 6 C. Pearls in a Row

    Educational Codeforces Round 6 C. Pearls in a Row 题意:一个3e5范围的序列:要你分成最多数量的子序列,其中子序列必须是只有两个数相同, 其余的数只能 ...

  8. Educational Codeforces Round 9

    Educational Codeforces Round 9 Longest Subsequence 题目描述:给出一个序列,从中抽出若干个数,使它们的公倍数小于等于\(m\),问最多能抽出多少个数, ...

  9. Educational Codeforces Round 37

    Educational Codeforces Round 37 这场有点炸,题目比较水,但只做了3题QAQ.还是实力不够啊! 写下题解算了--(写的比较粗糙,细节或者bug可以私聊2333) A. W ...

随机推荐

  1. Realsense Camera SDK 开发手记(一)

    0x01 第一次使用SDK写代码,有很多不懂的地方,在设备来之前把文档看了一下,大概明白了点,东平西凑大概写了点,但是当把设备连接上去进行测试的时候就出现了各种问题,用RealSenseCamera进 ...

  2. C#动态编程

    class Program { static void Main(string[] args) { Test(); } public static void Test() { //声明代码的部分 Co ...

  3. 暑假集训2016day3T1 欧拉回路(UOJ #117欧拉回路)(史上最全的欧拉回路纯无向图/有向图解析)

    原题……可惜不会……真是一只大蒟蒻…… ———————————————————————————————— 有一天一位灵魂画师画了一张图,现在要你找出欧拉回路,即在图中找一个环使得每条边都在环上出现恰好 ...

  4. Linux权限解释

    从左至右,第一位数字代表文件所有者的权限,第二位数字代表同组用户的权限,第三位数字代表其他用户的权限. 而具体的权限是由数字来表示的,读取的权限等于4,用r表示:写入的权限等于2,用w表示:执行的权限 ...

  5. IDA Pro使用

    当我们的光标在某个函数处时,按回车键就可以跳到这个函数所在的位置:

  6. 设置IIS下PHP环境的DOCUMENT_ROOT

    这两天把一网站架到了IIS服务器上,却发现在读取 $_SERVER['DOCUMENT_ROOT'] 的时候是空值.翻阅了PHP的文档,发现对该变量的解释为:“当前运行脚本所在的文档根目录.在服务器配 ...

  7. POJ 3020 Antenna Placement(无向二分图的最小路径覆盖)

    ( ̄▽ ̄)" //无向二分图的最小路径覆盖数=顶点总数-最大匹配数/2(最大匹配数=最小点覆盖数) //这里最大匹配数需要除以2,因为每两个相邻的*连一条边,即<u,v>和< ...

  8. Java 反射 Method的invoke回调调用任意方法

    Java 反射 Method的invoke回调调用任意方法 @author ixenos 关键子:Method.Field.invoke方法指针/函数指针.回调函数 invoke回调流程示例 0.由C ...

  9. Storm中-Worker Executor Task的关系

    Storm在集群上运行一个Topology时,主要通过以下3个实体来完成Topology的执行工作:1. Worker(进程)2. Executor(线程)3. Task 下图简要描述了这3者之间的关 ...

  10. mysql字段更改操作命令

    1) 加索引   mysql> alter table 表名 add index 索引名 (字段名1[,字段名2 …]); 例子: mysql> alter table employee ...