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. UNIX网络编程---TCP客户/服务器程序示例(五)

    一.概述 客户从标准输入读入一行文本,并写给服务器 服务器从网络输入读入这行文本,并回射给客户 客户从网络输入读入这行回射文本,并显示在标准输出上 二.TCP回射服务器程序:main函数 这里给了函数 ...

  2. C语言随笔_printf输出多行

    想在printf中,输出多行数据,如果写成下面这样: printf("line 1\n line 2\n line 3\n");编译器会报错“error C2001: newlin ...

  3. 剑指offer-面试题22.栈的压入,弹出序列

    题目:输入两个整数序列,第一个序列表示栈的压入顺序,请判断第 二个序列是否为该栈的弹出顺序.假设压入栈的所有数字均不相等. 例如序列1.2.3.4.5是某栈的压栈序列,序列4.5.3.2.1 是该压栈 ...

  4. Python 自动化脚本学习(三)

    函数 例子 def hello(): print("hello" + "world"); 有参数的函数 def hello(name): print(" ...

  5. Android学习总结——系统提示对话框(AlertDialog)

    new AlertDialog.Builder(MainActivity.this).setTitle("退出")//设置对话框标题 .setMessage("官人可是要 ...

  6. Alice and Bob(mutiset容器)

    Alice and Bob Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) T ...

  7. CF(441D Valera and Swaps)置换群

    题意:1-n的一个排列, p2, ..., pn,f(p)的定义是此排列要交换最少的数对能够回到原排列1,2,3,4...n.给一个排列p.要将其变换成f值为m的排列,问至少要交换几个数对,并输出字典 ...

  8. docker 实战---使用oracle xe作为开发数据库(六)

    oracle作为oltp的大佬,非常多行业应用都会用到它.那么在开发的过程中就不可避免的要使用oracle数据库,oracle数据库的版本号有好多,当中express版本号是免费的开发版.它的主要限制 ...

  9. Python 练习 —— 2048

    1. 引言 2048 这段时间火的不行啊,大家都纷纷仿造,"百家争鸣",于是出现了各种技术版本号:除了手机版本号,还有C语言版.Qt版.Web版.java版.C#版等,刚好我接触P ...

  10. angular在ie8下的一个bug

    昨天拿项目在ie8下测试,发现不少bug,其中有一个bug让我很不解,报了一个thead开头的bug,因为已经切回到linux下了,我就不报具体是什么bug了,鼓捣了半天,发现引用angular的应用 ...