466A.md (1199B)
1 Source: https://codeforces.com/problemset/problem/466/A 2 3 A. Cheap Travel 4 5 time limit per test 6 7 1 second 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 stdin 16 17 output 18 19 stdout 20 21 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? 22 23 Input 24 25 The single line contains four space-separated integers *n*, *m*, *a*, *b* (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. 26 27 Output 28 29 Print a single integer — the minimum sum in rubles that Ann will need to spend. 30 31 Examples 32 33 Input 34 35 ``` 36 6 2 1 2 37 ``` 38 39 Output 40 41 ``` 42 6 43 ``` 44 45 Input 46 47 ``` 48 5 2 2 3 49 ``` 50 51 Output 52 53 ``` 54 8 55 ``` 56 57 Note 58 59 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.