您的位置:首页 > 其它

Educational Codeforces Round 15_D. Road to Post Office

2016-07-30 01:41 417 查看
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=0;
scanf("%I64d%I64d%I64d%I64d%I64d",&d,&k,&a,&b,&t);
if(d<=k){printf("%I64d\n",d*a);return 0;}
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 0;
}
ll tpa=k*a+t,tpb=k*b;
if(tpa<tpb){
ll now=d/k;
ans+=tpa*now;
d%=k;
if(d==0){printf("%I64d\n",ans);return 0;}
}else{
ans+=d*b;
printf("%I64d\n",ans);
return 0;
}
tpa=d*a+t;
tpb=d*b;
if(tpa<tpb)ans+=tpa;else ans+=tpb;
printf("%I64d\n",ans);
return 0;
}
View Code

 

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: