codeforces-702D-Road to Post Office
来源:互联网 发布:celtx剧本写作软件 编辑:程序博客网 时间:2024/05/22 17:36
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.
这是一个sabi推公式的题
首先算出来每停一次所要话费的时间,然后会判断一下距离d,和所要停车修车的距离k的大小,如果d小于k,那么还停个屁啊,直接开车走咯,然后去算就好了,其中要判断一下停车修车的时间和走路话费的时间的大小
#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>using namespace std;typedef long long ll;int main(){ ll d,k,a,b,t; while(scanf("%lld%lld%lld%lld%lld",&d,&k,&a,&b,&t)!=EOF) { ll tt=a*k+t; ll sum=0; if(d<=k) { sum=d*a; } else { if(tt<b*k) { sum=(d/k)*a*k+t*((d)/k-1)+min( (d%k)*a+t,(d%k)*b); } else { sum=a*k+b*(d-k); } } printf("%I64d\n",sum); } return 0;}
- codeforces-702D-Road to Post Office
- Codeforces 702D - Road to Post Office
- Codeforces Problem 702D Road to Post Office(分类讨论)
- Codeforces 702D Road to Post Office(模拟 + 公式推导)
- CF 702D Road to Post Office
- Educational Codeforces Round 15 D. Road to Post Office
- CodeForces-702D Road to Post Office(初中数学脑洞题)
- Codeforces 702D Road to Post Office【捎带数学的思维题】
- Educational Codeforces Round 15 D. Road to Post Office (数学)
- Educational Codeforces Round 15 D Road to Post Office(分类讨论)
- CodeForces702D. Road to Post Office(二分or数学)
- CodeForces 34D Road Map
- Codeforces Gym100425 D. Toll Road
- CodeForces 828D High Road
- coderforces 702DRoad to Post Office
- CodeForces 831D Office Keys
- Codeforces 831 D Office Keys
- codeforces 831D Office Keys
- Fragment嵌套Fragment使用的一般框架
- 循环队列的优点缺点
- 验证哥德巴赫猜想
- Scala入门之面向接口编程
- JZOJ4588. 【NOI2016模拟7.7】冷战 + 按秩合并讲解
- codeforces-702D-Road to Post Office
- 设计模式-装饰者模式
- eclipse怎么查看开发包jar里源代码
- Linux -- 档案与目录管理
- Android自定义权限
- 【整理】getElementByID,getElementsByName,getElemtsByTagName的区别
- [Kubernetes]Docker的overlay网络模型
- java语言基础入门——多线程
- UNIX网络编程笔记(11)—UNIX域套接字