Codeforces 702D Road to Post Office(模拟 + 公式推导)

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 ≤ 10121 ≤ k, a, b, t ≤ 106a < 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.

这个题其实蛮简单的,可惜当时我头脑不清醒,加上智障智和钰神被上一题搞得有点焦虑,所以没有AC==


#include <iostream>

#include <cmath>
#include <string.h>
#include<string>
#include <algorithm>
#include <vector>
#include<math.h>
#include<set>
#include<string.h>
#include <stdio.h>
#define ll long long int
#define cla(a) memset(a,0,sizeof(a))
using namespace std;
int main()
{
	ll k, a, e, r, p;
	while (cin >> k >> a >> e >> r >> p)
	{
		ll ans = 0;
		if(k<=a)
		{ 
			ans = k*e;
		}
		else
		{
			if (a*e + p <= a*r)
			{
				ans = (k / a)*(a*e + p)-p;
				ll la = k / a;
				la = k - a*la;
				if (la*e + p <= la*r)
				{
					ans += la*e + p;
				}
				else
				{
					ans += la*r;
				}
			}
			else
			{
				ans = a*e;
				k -= a;
				ans += k*r;
			}
		}
		cout << ans << '\n';
	}
	return 0;
}

//by swust_t_p
全部评论

相关推荐

找不到工作死了算了:没事的,雨英,hr肯主动告知结果已经超越大部分hr了
点赞 评论 收藏
分享
10-07 23:57
已编辑
电子科技大学 Java
八街九陌:博士?客户端?开发?啊?
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务