cf466A Cheap Travel

时间:2023-02-07 12:51:45
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&period; Cheap Travel 解题报告

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

  2. Codeforces Round &num;266 &lpar;Div&period; 2&rpar;

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

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

  4. 图论 - Travel

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

  5. 【BZOJ-1576】安全路径Travel Dijkstra &plus; 并查集

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

  6. Linux inode &amp&semi;&amp&semi; Fast Directory Travel Method&lpar;undone&rpar;

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

  7. HDU - Travel

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

  8. 2015弱校联盟&lpar;1&rpar; - I&period; Travel

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

  9. ural 1286&period; Starship Travel

    1286. Starship Travel Time limit: 1.0 secondMemory limit: 64 MB It is well known that a starship equ ...

随机推荐

  1. bug 汇总

    联通营业厅充话费无法在线支付,chrome Python 64位安装包 win7 64 windows 10 右键菜单 Android studio IE11 layout

  2. javascript 数组实例

    在遍历数组时, 如果想要排除 null / undefined 和 不存在的元素时,代码如下: for ( var i = 0; i < a.length; i++ ){ //跳过null / ...

  3. HealthKit开发快速入门教程之HealthKit框架体系创建健康AppID

    HealthKit开发快速入门教程之HealthKit框架体系创建健康AppID HealthKit开发准备工作 在开发一款HealthKit应用程序时,首先需要讲解HealthKit中有哪些类,在i ...

  4. Deep learning的一些教程 (转载)

    几个不错的深度学习教程,基本都有视频和演讲稿.附两篇综述文章和一副漫画.还有一些以后补充. Jeff Dean 2013 @ Stanford http://i.stanford.edu/infose ...

  5. cass实体编码列表

    地物名称 编码 图层 类别 参数一 参数二 实体类型 三角点 131100 KZD 20 gc113 3 SPECIAL,1 三角点分数线 131110 KZD 附 LINE 三角点高程注记 1311 ...

  6. Android客户端实现七牛云存储文件上传

    1.简单文件上传  上传模型如下. 1.1获得Token 不管是简单文件上传,还是分片上传.断点续传 都需要首先访问服务器,以获得上传凭证信息Token..用于测试时,可以用本地模拟Token信息(有 ...

  7. mono for android工具下载

    http://www.wuleba.com/25510.html Windows平台:http://xamarin.com/installer_assets/v3/Windows/Universal/ ...

  8. 强大的Cmder

    why 漂亮,包装并美化了各个shell 带task功能,能记忆,能执行脚本 配合win10的bash,能实现类似xshell的功能 注意点 需要注意的一点,Cmder来源于另外一个项目ConEmu, ...

  9. Java代码的编译与反编译那些事儿

    原文:Java代码的编译与反编译那些事儿 编程语言 在介绍编译和反编译之前,我们先来简单介绍下编程语言(Programming Language).编程语言(Programming Language) ...

  10. iOS架构模式浅析

    这是以前旧博客在13年规划写的一个系列,写了一部分内容,还没有完成.现在重新整理编写.计划从基础知识六大设计原则.设计模式中类的关系开始,然后会对iOS开发中的常用架构模式进行介绍,最后对GoF的23 ...