4627: Road to Post Office

内存限制:256 MB 时间限制:2 S 标准输入输出
题目类型:传统 评测方式:文本比较 上传者:
提交:2 通过:2

题目描述

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.


瓦西里有一辆车,他想从家里去邮局。他需要经过的距离等于d公里。

瓦西里的车不是新的——每行驶k公里就坏一次,瓦西里需要t秒来修理它。修理完他的车后,瓦西里伊可以再次驾驶(但在行驶k公里后,它会再次坏,依此类推)。在旅程的开始,这辆车刚从修理站出来。

瓦西里开车一公里需要一秒,步行一公里需要b秒(a<b)。

你的任务是找到最短的时间,之后瓦西里就能到达邮局。想想瓦西里在每一个时刻都可以离开他的车,开始步行。


输入格式

第一行包含5个正整数d、k、a、b、t(1≤d≤1012;1≤k,a、b,t≤106;a<b),其中:

d−从家到邮局的距离;

k−车辆在断裂前能够行驶的距离;

a−瓦西里开车行驶1公里所花费的时间;

b−瓦西里步行1公里所花费的时间;

t−瓦西里用来修理汽车的时间。

输出格式

打印瓦西里到达邮局的最短时间。

输入样例 复制

5 2 1 4 10

输出样例 复制

14

数据范围与提示

在第一个例子中,瓦西里需要在汽车上行驶前2公里(2秒内),然后步行3公里(12秒内)。所以答案等于14秒。

在第二个例子中,瓦西里需要在车上行驶前2公里(2秒内),然后修理他的车(5秒内),并在车上再行驶2公里(在2秒内)。之后,他需要步行1公里(4秒内)。所以答案等于13秒。