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.

题目链接:http://codeforces.com/contest/702/problem/D

水题,分情况讨论即可。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int main()
{
long long d,k,a,b,t;
cin >> d >> k >> a >> b >> t;
long long ans = ;
if(d <= k)
{
ans = d*a;
}
else
{
if(a*k+t >= k*b)
{
ans =k*a+(d-k)*b;
}
else
{
long long n = d/k;
ans+=n*k*a+(n-)*t;
long long dd = d - n*k;
ans+=min(dd*b,t+dd*a);
}
}
cout << ans;
return ;
}

Codeforces Educational Codeforces Round 15 D. Road to Post Office的更多相关文章

  1. 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 standa ...

  2. Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings

    Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings 题目连接: http://cod ...

  3. Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes

    Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes 题目连接: http://code ...

  4. Codeforces Educational Codeforces Round 15 C. Cellular Network

    C. Cellular Network time limit per test 3 seconds memory limit per test 256 megabytes input standard ...

  5. Codeforces Educational Codeforces Round 15 A. Maximum Increase

    A. Maximum Increase time limit per test 1 second memory limit per test 256 megabytes input standard ...

  6. Codeforces Educational Codeforces Round 15 E - Analysis of Pathes in Functional Graph

    E. Analysis of Pathes in Functional Graph time limit per test 2 seconds memory limit per test 512 me ...

  7. Codeforces Educational Codeforces Round 3 B. The Best Gift 水题

    B. The Best Gift 题目连接: http://www.codeforces.com/contest/609/problem/B Description Emily's birthday ...

  8. codeforces Educational Codeforces Round 5 A. Comparing Two Long Integers

    题目链接:http://codeforces.com/problemset/problem/616/A 题目意思:顾名思义,就是比较两个长度不超过 1e6 的字符串的大小 模拟即可.提供两个版本,数组 ...

  9. codeforces Educational Codeforces Round 16-E(DP)

    题目链接:http://codeforces.com/contest/710/problem/E 题意:开始文本为空,可以选择话费时间x输入或删除一个字符,也可以选择复制并粘贴一串字符(即长度变为两倍 ...

随机推荐

  1. 自定义View(7)官方教程:自定义View(含onMeasure),自定义一个Layout(混合组件),重写一个现有组件

    Custom Components In this document The Basic Approach Fully Customized Components Compound Controls ...

  2. apache for mac OX S 10.10

    mac下如何针对 apache 设置虚拟目录呢?可能很多人都设置过,但也都不太会,每次都是网上找文章啥的.这里,我自己整理了一点,希望可以帮到大家. 还原 httpd.conf 配置文件 如果,你现在 ...

  3. JS生成指定长度的随机数

    /** * 生成指定长度的UUID * @param len * @param radix * @returns uuid * eg: createUUID(8, 2) "01001010& ...

  4. jsonp从服务器读取数据并且予以显示

    之前看了许多的关于jsonp的文章,大多是讲的比较的模糊的,下面是我的个人的理解! 基于这样的一段代码,做下解释: 这是在jsonp中读取数据的时候(取出来当然是json的格式json格式不清楚的,可 ...

  5. URAL1133. Fibonacci Sequence(二分)

    1133 刚开始还用记忆化推了下公式 后来发现数是非常大的 二分 然后就是精度错误 中间值会很大 乱七八糟的改 #include <iostream> #include<cstdio ...

  6. 【笨嘴拙舌WINDOWS】实践检验之按键精灵【Delphi】

    通过记录键盘和鼠标位置和输入信息,然后模拟发送,就能够创建一个按键精灵! 主要代码如下: library KeyBoardHook; { Important note about DLL memory ...

  7. 51nod1537 分解

    http://blog.csdn.net/qingshui23/article/details/52350523 详细题解%%%%对矩阵乘法的不熟悉.以及不会推公式 #include<cstdi ...

  8. java基础 (记事本编写hello world,path,classpath,java的注释符)

    一:java的基本信息 jre 是指java运行环境,jdk 是指 java 开发工具集(并且里面是自带有jre运行环境的) jvm是指java的虚拟机 java的源代码的后缀名是 .java (例如 ...

  9. 对比C++中的指针和引用

    指针和引用在形式上比较好区分,由于有很多相似的功能,因此在使用上容易混淆.因此有必要对指针和引用进行对比,以便于在使用时使程序正确高效. 1.引用不可以为空,而指针可以为空. 我们知道引用是对象的别名 ...

  10. centos 升级php、mysql(webtatic)

    1)定义使用webtatic源 rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-5.noarch.rpm (ps: ...