# Cheap Travel（暴力求解法）

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

#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;

#define MAX_N 1000005//可由数据推得最大票价不会超过这个数

int n,m,a,b,ans;

int main()
{
while(cin>>n>>m>>a>>b)
{
ans=MAX_N;
for(int i=0;i<=n;i++)
{
int j=(n-i)/m + bool((n-i)%m);

ans = min(ans,i*a+j*b);
}

cout<<ans<<endl;
}
return 0;
}

• 本文已收录于以下专栏：

## Codeforces Cheap Travel

import java.util.Scanner; public class CheapTravel { public static void main(String[] args) { S...
• Lutte_
• 2017年06月22日 09:57
• 94

## A. Cheap Travel

• jj12345jj198999
• 2014年09月13日 19:58
• 555

## CodeForces 466A Cheap Travel

Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Description A...
• ALONENanGong
• 2016年01月14日 10:33
• 167

## 【CODEFORCES】 A. Cheap Travel

A. Cheap Travel time limit per test 1 second memory limit per test 256 megabytes in...
• S_Black
• 2015年02月06日 16:10
• 472

## 466A. Cheap Travel

A. Cheap Travel time limit per test 1 second memory limit per test 256 megabytes input standar...
• daima66699
• 2017年01月25日 14:45
• 127

## cf466A Cheap Travel

A. Cheap Travel time limit per test 1 second memory limit per test 256 megabytes in...
• zhb1997
• 2014年09月13日 22:06
• 368

## Codeforces 466A - Cheap Travel

A. Cheap Travel time limit per test 1 second memory limit per test 256 megabytes input standar...
• Nicholafs
• 2017年07月19日 10:31
• 96

## CodeForces 466A Cheap Travel

Description Ann has recently started commuting by subway. We know that a one ride subway ticket cos...
• geekdoe
• 2015年12月31日 16:53
• 326

## codeforces——466A——Cheap Travel

A. Cheap Travel time limit per test 1 second memory limit per test 256 megabytes input s...
• lose__way
• 2017年05月20日 17:19
• 120

## Codeforces 466 A. Cheap Travel

A. Cheap Travel time limit per test 1 second memory limit per test 256 megabytes in...
• u012797220
• 2014年09月13日 10:21
• 1818

举报原因： 您举报文章：Cheap Travel（暴力求解法） 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)