Ann has recently started commuting by subway. We know that a one ride subway ticket costsARubles. Besides, Ann found out that she can buy a special ticketMRides (she can buy it several times). It costsBRubles. Ann did the math; she will need to use subwayNTimes. help Ann, tell her what is the minimum sum of money she will have to spend to makeNRides?
Input
The single line contains four space-separated IntegersN,M,A,B(1? ≤?N,?M,?A,?B? ≤? (1000)-the number of rides Ann has planned, the number of rides covered byMRide ticket, the price of a one ride ticket and the price ofMRide 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. Assume that you need a yuan for one subway station, B yuan for M stations, and the minimum money required for N stations: N is not big, therefore, we can enumerate the number of stations and the number of other stations.#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <vector>using namespace std;const int inf = 0x3f3f3f3f;int main() {int n, m, a, b;scanf("%d%d%d%d", &n, &m, &a, &b);int ans = inf;for (int i = 0; i <= n; i++) {int numM = (n - i + m - 1) / m;int cur = a * i + numM * b;if (cur < ans)ans = cur;}printf("%d\n", ans);return 0;}
Codeforces round #266 (Div. 2) A. Cheap travel