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.

题意:d,k,a,b,t

  • d — the distance from home to the post office; 从家到邮局的距离
  • k — the distance, which car is able to drive before breaking;车最多能开k
  • 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.修车的速度

求从家到达邮局的最小时间。

题解:题目保证a<b 第一段肯定是开车的  特判处理

之后的路程以k为分段 比较 修车-开车所花的时间( t+a*k)与这一段步行所花的时间(b*k) 取min

最后不足k的一段x 所花的时间为 min(t+a*x,b*x); 求和ans输出.

 /******************************
code by drizzle
blog: www.cnblogs.com/hsd-/
^ ^ ^ ^
O O
******************************/
//#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<map>
#include<algorithm>
#include<queue>
#define ll __int64
using namespace std;
ll d,k,a,b,t;
int main()
{
scanf("%I64d %I64d %I64d %I64d %I64d",&d,&k,&a,&b,&t);
if(d<=k)
{
printf("%I64d\n",d*a);
return ;
}
ll ans=k*a;
d-=k;
ll exm=d/k;
ll plu=d%k;
ans=ans+exm*min(t+a*k,b*k);
ans=ans+min(t+a*plu,b*plu);
printf("%I64d\n",ans);
return ;
}

Educational Codeforces Round 15 D 数学推公式的更多相关文章

  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 15 C. Cellular Network

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

  3. 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 ...

  4. 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. Educational Codeforces Round 15 C 二分

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

  6. Educational Codeforces Round 15 A dp

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

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

  8. Codeforces 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 ...

  9. Educational Codeforces Round 15 (A - E)

    比赛链接:http://codeforces.com/contest/702 A. Maximum Increase A题求连续最长上升自序列. [暴力题] for一遍,前后比较就行了. #inclu ...

随机推荐

  1. 给出一个长度为n的数列,请对于每一个数,输出他右边第一个比他大的数。n<=100000.

    RT,一个ppt里看到的题,不过没讲做法.百度上基本搜不到.自己想了个做法,理论上可行,复杂度也是O(nlogn). 首先,做一次RMQ,求区间最大值. 对于任意一个数s[i],可以用logn的时间求 ...

  2. Redis系列-存储篇sorted set主要操作函数小结

    redis支持有序集合,即sorted set.sorted set在set的基础上,增加了排序属性,是set的升级版.这里简要谈谈sorted set的常用函数: 1)insert a)  zadd ...

  3. 【转】 linux 安装nginx及编译参数详解

    版权声明:本文为博主原创文章,未经博主允许不得转载. 从官网下载一个nginx 的tar.gz 版. 安装方式使用make 安装 第一步:解压 tar -zxvf  nginx-1.7.4.tar.g ...

  4. JAVA之关于super的用法

    JAVA之关于super的用法   路漫漫其修远兮,吾将上下而求索.——屈原<离骚> 昨天写this用法总结的时候,突然产生了一个问题,请教别人之后,有了自己的一点认识.还是把它写下来,为 ...

  5. 常错-UIScrollView中得图片不能被拖动

    经常在开发中,发现自己UIScrollView里面的图片不能被拖动 在这里做个备忘,第一种可能是contentSize没有设置,第二种可能是contentSize设置的太小了. 测试后发现,与user ...

  6. pyqt5 笔记(四)cx_Freeze 实现代码打包exe

    下载地址:https://pypi.python.org/pypi/cx_Freeze 教程:http://www.cnblogs.com/xinzaitian/archive/2010/12/10/ ...

  7. 《day13--异常的进阶和包的使用》

    //101-finally的使用&102-finally的使用场景 /* 需求:有一些特定的代码,无论异常是否发生,都需要执行, 因为异常会引发程序的跳转,导致有些语句执行不到,无法满足这个需 ...

  8. 理解Mac和iOS中的 Event 处理

    根据现在的理解,我把event处理分为5部分,第一是,Event处理的Architecture:第二是,Event的Dispatch到first responder之前: 第三是,Event从firs ...

  9. hd oj2015

    #include "stdio.h"int main(){ int n,m,k,num,i,sum=0; while(~scanf("%d%d",&n, ...

  10. HttpApplication 类,HttpApplicationState 类

    HttpApplication 类 定义 ASP.NET 应用程序中的所有应用程序对象共有的方法.属性和事件.此类是用户在 Global.asax 文件中所定义的应用程序的基类. https://ms ...