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.

题意:一个人要去邮局,他有一辆车,但是车很旧,每开K千米需要修理时间T,开车1千米的时间为A,步行的时间为B,求最少的时间到邮局;

思路:简单数学题;K千米如果开车+修理的时间小就选择车,否则就步行;

#include<bits/stdc++.h>
using namespace std;
#define ll __int64
#define esp 0.00000000001
const int N=3e3+,M=1e6+,inf=1e9+,mod=;
int main()
{
ll d,k,a,b,t;
scanf("%I64d%I64d%I64d%I64d%I64d",&d,&k,&a,&b,&t);
ll tc=t+k*a;
ll tw=k*b;
if(d<=k)
{
printf("%I64d\n",d*a);
return ;
}
ll ans=k*a;
d-=k;
ans+=(d/k)*min(tc,tw);
d=d%k;
ans+=min(d*b,t+a*d);
printf("%I64d\n",ans);
return ;
}

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

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

  2. Educational Codeforces Round 15 Road to Post Office

    Road to Post Office 题意: 一个人要从0走到d,可以坐车走k米,之后车就会坏,你可以修或不修,修要花t时间,坐车单位距离花费a时间,走路单位距离花费b时间,问到d的最短时间. 题解 ...

  3. Educational Codeforces Round 15 (A - E)

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

  4. Educational Codeforces Round 15 D 数学推公式

    D. Road to Post Office time limit per test 1 second memory limit per test 256 megabytes input standa ...

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

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

  7. Educational Codeforces Round 15 C. Cellular Network(二分)

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

  8. Educational Codeforces Round 15 C 二分

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

  9. Educational Codeforces Round 15 A dp

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

随机推荐

  1. 技术总结PHP+微信

      ajax: //获取商品属性数据 function initGoodsAttr(){   $.ajax({       type: 'GET',       url:"<?php  ...

  2. hive表信息查询:查看表结构、表操作等

    转自网友的,主要是自己备份下 有时候不记得! 问题导读:1.如何查看hive表结构?2.如何查看表结构信息?3.如何查看分区信息?4.哪个命令可以模糊搜索表 1.hive模糊搜索表 show tabl ...

  3. CentOS 7.4系统优化/安装软件

    源改为国内源 阿里云yum源 https://opsx.alibaba.com/mirror 清华yum源 https://mirrors.tuna.tsinghua.edu.cn/ 网易163yum ...

  4. Android系统移植与调试之------->如何修改Android系统默认显示【开发者选项】并默认打开【USB调试】和【未知来源】开关

    今天有个用户对[设置]有个特殊的要求,即: 1.开机的时候默认显示[开发者选项]并打开[USB调试]开关    ([Developer options]-->[USB debugging]) 2 ...

  5. SAP后勤模块实施攻略——1.ERP和SAP

    近日接到任务,看完乐立骏老师的SAP后勤模块实施攻略这本书,现在把第一章内容简单整理.第一章讲的是关于ERP和SAP的介绍. 1.ERP E:Enterprise / 企业 R:Resource / ...

  6. studio显示Surface: getSlotFromBufferLocked: unknown buffer: 0xa2a58be0

    根据查询外网资料来看,出现这个错误的原因大致是换个模拟器或者物理机就可以了. 因为我使用的是安卓6.0,貌似都会出现这类的问题. 但是不影响程序运行.

  7. NPOI 导入 导出

    using NPOI.XSSF.UserModel;   using System.IO; 导入 /// <summary> /// Excel转换DataTable /// </s ...

  8. 爬虫五 Beautifulsoup模块详细

    一.基本使用 from bs4 import BeautifulSoup htmlCharset = "GB2312" soup=BeautifulSoup(html_doc,'l ...

  9. 解释一下python中的继承

    当一个类继承另一个类,它就被称为一个子类/派生类,继承父类/基类/超类.它会继承/获取所有类成员(属性和方法) 继承能让我们重新使用代码,也能更容易的创建和维护应用 单继承:一个类继承单个基类 多继承 ...

  10. Android Integer.parseInt java.lang.NumberFormatException: Invalid int解决方法

    解决方法: http获取的字符串minutes去空字符串处理minutes.replaceAll("\\D+","").replaceAll("\r& ...