Educational Codeforces Round 15 D. Road to Post Office 数学

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,步行的时间为B,求最少的时间到邮局;

思路:简单数学题;K千米如果开车+修理的时间小就选择车,否则就步行;

#include<bits/stdc++.h>
using namespace std;
#define ll __int64
#define esp 0.00000000001
const int N=3e3+,M=1e6+,inf=1e9+,mod=;
int main()
{
ll d,k,a,b,t;
scanf("%I64d%I64d%I64d%I64d%I64d",&d,&k,&a,&b,&t);
ll tc=t+k*a;
ll tw=k*b;
if(d<=k)
{
printf("%I64d\n",d*a);
return ;
}
ll ans=k*a;
d-=k;
ans+=(d/k)*min(tc,tw);
d=d%k;
ans+=min(d*b,t+a*d);
printf("%I64d\n",ans);
return ;
}
上一篇:PHP 7 探针的安装与测试


下一篇:Android学习路径(十)怎么会Action Bar堆放在布局