A. Cheap Travel
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Ann has recently started commuting by subway. We know that a one ride subway ticket costs a rubles. Besides, Ann found out that she can buy a special ticket for m rides (she can buy it several times). It costs b rubles. Ann did the math; she will need to use subway n times. Help Ann, tell her what is the minimum sum of money she will have to spend to make n rides?

Input

The single line contains four space-separated integers nmab (1 ≤ n, m, a, b ≤ 1000) — the number of rides Ann has planned, the number of rides covered by the m ride ticket, the price of a one ride ticket and the price of an m ride ticket.

Output

Print a single integer — the minimum sum in rubles that Ann will need to spend.

Sample test(s)
input
6 2 1 2
output
6
input
5 2 2 3
output
8
Note

In the first sample one of the optimal solutions is: each time buy a one ride ticket. There are other optimal solutions. For example, buy three m ride tickets.

题意是要买n张票,可以买1张价格是a,也可以买m张价格是b

忘记考虑全买m张的最后剩下来直接买m张比一张一张更优的情况了……wa了两次

#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<ctime>
#define LL long long
using namespace std;
LL n,m,a,b;
inline LL read()
{
LL x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
int main()
{
n=read();m=read();a=read();b=read();
printf("%d",min(min(n*a,(n/m)*b+(n%m)*a),(n/m+1)*b));
}

  

cf466A Cheap Travel的更多相关文章

  1. codeforces 466A. Cheap Travel 解题报告

    题目链接:http://codeforces.com/problemset/problem/466/A 题目意思:一个 ride 需要 a 卢布,m 个 ride 需要 b 卢布,这两种方案都可以无限 ...

  2. Codeforces Round #266 (Div. 2)

    http://codeforces.com/contest/466 噗,b没写出来啊.a写完后过了40分钟了啊,罚时4次啊!果然太弱 总结: a题看错题,没有考虑m>=n其实也是可行的,导致调了 ...

  3. [codeforces] 暑期训练之打卡题(二)

    每个标题都做了题目原网址的超链接 Day11<Given Length and Sum of Digits...> 题意: 给定一个数 m 和 一个长度 s,计算最大和最小在 s 长度下, ...

  4. cheap gucci bags for women finish fashion jewellery has to move

    Is certainly his dresser seem or dress creation process into video clip. Bus dropped???? Especially ...

  5. 图论 - Travel

    Travel The country frog lives in has nn towns which are conveniently numbered by 1,2,…,n. Among n(n− ...

  6. 【BZOJ-1576】安全路径Travel Dijkstra + 并查集

    1576: [Usaco2009 Jan]安全路经Travel Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 1044  Solved: 363[Sub ...

  7. Linux inode && Fast Directory Travel Method(undone)

    目录 . Linux inode简介 . Fast Directory Travel Method 1. Linux inode简介 0x1: 磁盘分割原理 字节 -> 扇区(sector)(每 ...

  8. HDU - Travel

    Problem Description Jack likes to travel around the world, but he doesn’t like to wait. Now, he is t ...

  9. 2015弱校联盟(1) - I. Travel

    I. Travel Time Limit: 3000ms Memory Limit: 65536KB The country frog lives in has n towns which are c ...

随机推荐

  1. CSS基础-引入方法,选择器,继承

    一.CSS引入方法:行内式.嵌入式.导入式.链接式. 1.行内式. 即:在标签的style属性中设定CSS样式. 例子:<div style="行内式</div> 2.嵌入 ...

  2. 求解答,Android源码编译时怎样添加第三方jar包

    各位大神好,遇到的问题如标题. 我用Eclipse写了一个android工程,但是这个工程需要到SDK的隐藏类,所有想在源码下编译,但是每次mm之后,都会出现错误,提示是找不到对应的类. 我需要加入的 ...

  3. 【转】android 电容屏(一):电容屏基本原理篇

    关键词:android  电容屏 tp  ITO 平台信息:内核:linux2.6/linux3.0系统:android/android4.0 平台:S5PV310(samsung exynos 42 ...

  4. 小函数,大智慧,php的isset和empty

    Disset()函数 一般用来检测变量是否设置  bool isset ( mixed var [, mixed var [, ...]] )  功能:检测变量是否设置  返回值:  FALSE  N ...

  5. 频繁模式挖掘apriori算法介绍及Java实现

    频繁模式是频繁地出如今数据集中的模式(如项集.子序列或者子结构).比如.频繁地同一时候出如今交易数据集中的商品(如牛奶和面包)的集合是频繁项集. 一些基本概念 支持度:support(A=>B) ...

  6. poj 2429 Pollard_rho大数分解

    先对lcm/gcd进行分解,问题转变为从因子中选出一些数相乘,剩下的数也相乘,要求和最小. 这里能够直接搜索,注意一个问题,因为同样因子不能分配给两边(会改变gcd)所以能够将同样因子合并,这种话,搜 ...

  7. iOS 字体设置

    使用无衬线字体 body {     font-family: "Helvetica Neue", Helvetica, STHeiTi, sans-serif; }  iOS 4 ...

  8. windows下sqlplus / as sysdba报ora-12560的解决方法

    环境:win7_64位.数据库版本ORACLE11G_R2 在CMD窗口,使用下面三个命令可正常连接数据库:C:\Users\Administrator> sqplus /nolog C:\Us ...

  9. 记录ASP.NET页面表单初始状态(主要是为了前台可以根据这个判断页面是否变动了)

    把页面表单状态记录到HiddenField中. 这里只提供后台代码, 前台逻辑根据需求自由定义. 存放值的ViewState: protected Dictionary<string, stri ...

  10. asp.net 常用的3中身份验证

    1. windows验证: IIS根据应用程序的设置来进行身份验证,要使用这中验证方式,必须禁止使用匿名用户登录. 2. Forms验证: 通过Cookies来保存用户凭证,对未登录的用户 重定向到自 ...