CF702D.Road to Post Office

普及+/提高

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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.

瓦西里有一辆汽车,他想从家前往邮局。他需要行驶的距离为 dd 千米。

瓦西里的汽车不是新车——每行驶 kk 千米就会抛锚一次,而瓦西里需要 tt 秒来修理它。修好后,瓦西里可以继续驾驶(但再行驶 kk 千米后又会抛锚,如此反复)。出发时,汽车刚从维修站修好。

瓦西里驾车行驶 1 千米需耗时 aa 秒,步行 1 千米需耗时 bb 秒(其中 a<ba < b)。

你的任务是求出瓦西里抵达邮局所需的最短时间。注意:在任意时刻,瓦西里都可以弃车改为步行。

输入格式

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.

第一行包含 5 个正整数 dd、kk、aa、bb、tt(1 ≤ d ≤ 10121 \le d \le 10^{12};1 ≤ k, a, b, t ≤ 1061 \le k, a, b, t \le 10^6;a < ba < b),其中:

  • dd —— 从家到邮局的距离;
  • kk —— 汽车在损坏前能够行驶的距离;
  • aa —— 瓦西里驾驶汽车每公里所花费的时间;
  • bb —— 瓦西里步行每公里所花费的时间;
  • tt —— 瓦西里修理汽车所花费的时间。

输出格式

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

输出瓦西里能够到达邮局的最短时间。

输入输出样例

  • 输入#1

    5 2 1 4 10

    输出#1

    14
  • 输入#2

    5 2 1 4 5

    输出#2

    13

说明/提示

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.

在第一个例子中,瓦西里需要先开车行驶前 2 千米(耗时 2 秒),然后步行 3 千米(耗时 12 秒)。因此答案为 14 秒。

在第二个例子中,瓦西里需要先开车行驶前 2 千米(耗时 2 秒),然后修车(耗时 5 秒),再继续开车行驶 2 千米(耗时 2 秒)。之后,他需要步行 1 千米(耗时 4 秒)。因此答案为 13 秒。

输入解题思路,AI测评打分。不知道怎么写?

首页