codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

1214A.md (2023B)


      1 Source: https://codeforces.com/problemset/problem/1214/A
      2 
      3 A. Optimal Currency Exchange
      4 
      5 time limit per test
      6 
      7 1.5 seconds
      8 
      9 memory limit per test
     10 
     11 512 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 Andrew was very excited to participate in Olympiad of Metropolises. Days flew by quickly, and Andrew is already at the airport, ready to go home. He has $n$ rubles left, and would like to exchange them to euro and dollar bills. Andrew can mix dollar bills and euro bills in whatever way he wants. The price of one dollar is $d$ rubles, and one euro costs $e$ rubles.
     22 
     23 Recall that there exist the following dollar bills: $1$, $2$, $5$, $10$, $20$, $50$, $100$, and the following euro bills — $5$, $10$, $20$, $50$, $100$, $200$ (note that, in this problem we do not consider the $500$ euro bill, it is hard to find such bills in the currency exchange points). Andrew can buy any combination of bills, and his goal is to minimize the total number of rubles he will have after the exchange.
     24 
     25 Help him — write a program that given integers $n$, $e$ and $d$, finds the minimum number of rubles Andrew can get after buying dollar and euro bills.
     26 
     27 Input
     28 
     29 The first line of the input contains one integer $n$ ($1 \leq n \leq 10^8$) — the initial sum in rubles Andrew has.
     30 
     31 The second line of the input contains one integer $d$ ($30 \leq d \leq 100$) — the price of one dollar in rubles.
     32 
     33 The third line of the input contains integer $e$ ($30 \leq e \leq 100$) — the price of one euro in rubles.
     34 
     35 Output
     36 
     37 Output one integer — the minimum number of rubles Andrew can have after buying dollar and euro bills optimally.
     38 
     39 Examples
     40 
     41 Input
     42 
     43 ```
     44 100
     45 60
     46 70
     47 ```
     48 
     49 Output
     50 
     51 ```
     52 40
     53 ```
     54 
     55 Input
     56 
     57 ```
     58 410
     59 55
     60 70
     61 ```
     62 
     63 Output
     64 
     65 ```
     66 5
     67 ```
     68 
     69 Input
     70 
     71 ```
     72 600
     73 60
     74 70
     75 ```
     76 
     77 Output
     78 
     79 ```
     80 0
     81 ```
     82 
     83 Note
     84 
     85 In the first example, we can buy just $1$ dollar because there is no $1$ euro bill.
     86 
     87 In the second example, optimal exchange is to buy $5$ euro and $1$ dollar.
     88 
     89 In the third example, optimal exchange is to buy $10$ dollars in one bill.