CF702D.Road to Post Office

普及/提高-

通过率:0%

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 dd kilometers.

Vasiliy's car is not new — it breaks after driven every kk kilometers and Vasiliy needs tt seconds to repair it. After repairing his car Vasiliy can drive again (but after kk 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 aa seconds, to walk one kilometer on foot he needs bb 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.

输入格式

The first line contains 5 positive integers d,k,a,b,td,k,a,b,t ( 1<=d<=10121<=d<=10^{12} ; 1<=k,a,b,t<=1061<=k,a,b,t<=10^{6} ; a<b ), where:

  • dd — the distance from home to the post office;
  • kk — the distance, which car is able to drive before breaking;
  • aa — the time, which Vasiliy spends to drive 1 kilometer on his car;
  • bb — the time, which Vasiliy spends to walk 1 kilometer on foot;
  • tt — the time, which Vasiliy spends to repair his car.

输出格式

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.

首页