AmountApproximation
SRM 274 · 2005-11-23 · by Andrew_Lazarev
Problem Statement
We must pay D dollars. Unfortunately, we only have bills of two denominations: p1 dollars and p2 dollars. So, we want to overpay as little as possible.
You will be given
Constraints
- D will be between 1 and 1000000000 (109), inclusive.
- p1 will be between 1 and 1000000000 (109), inclusive.
- p2 will be between 1 and 1000000000 (109), inclusive.
17 7 9 Returns: 18
18 = 7 * 0 + 9 * 2
17 7 13 Returns: 20
20 = 7 * 1 + 13 * 1
21 7 13 Returns: 21
21 = 7 * 3 + 13 * 0
37 9 17 Returns: 43
43 = 9 * 1 + 17 * 2
287341 2345 7253 Returns: 287398
287398 = 2345 * 104 + 7253 * 6
Submissions are judged against all 138 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class AmountApproximation with a public method int approximate(int D, int p1, int p2) · 138 test cases · 2 s / 256 MB per case