Problem E
Sjálfsalastuð
Languages
en
is
At Reykjavík University a lot of computer science research gets done. To keep the researchers active and good, they need to be fed a lot of soda and it falls to the head of the department to go to the vending machine and buy soda for all of the employees. As they are very busy, they usually buy more than one can per trip.
The vending machines at RU accept only 100 kr, 50 kr and 10 kr coins and give change in as few coins as possible. The vending machines also only serve one can at a time.
Because of the importance of the research being conducted, RU has agreed to sell the cans at 80 kr a piece. The head of the department finds it very boring to feed coins into the machine, so they ask you to write a program that when given the number of cans they need to buy and the amount they have of each denomination of coin, finds the least number of coins that have to be fed into the machine to get all the cans. We can assume that the coins are worth enough to pay for all the cans.
Input
The input contains four integers separated by spaces. The first number $1 \leq C \leq 150$ gives the number of cans that the head of the department intends to buy. The next three numbers $n_{10}$, $n_{50}$ and $n_{100}$ gives the number of 10 kr, 50 kr and 100 kr coins they have, where $0 \leq n_{10} \leq 500$, $0 \leq n_{50} \leq 100$ and $0 \leq n_{100} \leq 50$.
Output
Print a single integer denoting the minimum number of coins that the head of the department needs to feed into the vending machine.
Explanation of Sample Inputs
In the first sample there are two 10 kr coins, one 50 kr coin and one 100 kr coin available to buy two cans. The 100 kr coin is used to buy the first can which returns two 10 kr coins. At this point one coin has been used. The 50 kr coin along with three 10 kr coins are then used to buy the second can. This takes four coins, so the total count is five coins.
In the second sample there is one 10 kr coin, four 50 kr coins and one 100 kr coin available to buy two cans. The first can is paid for with the 100 kr coin and gets two 10 kr coins in return. Then two 50 kr coins are used to buy the second can, again getting two 10 kr coins in return. This uses three coins in total.
In the third sample there are 200 10 kr coins and three 50 kr coins. The first three cans are bought with one 50 kr coin and three 10 kr coins. This uses a total of $3 \cdot 4 = 12$ coins. Then there are only 10 kr coins left for the last 17 cans. Thus each can takes 8 coins so it takes $8 \cdot 17 = 136$ coins to buy the last $17$ cans. To buy all $20$ cans it thus took $136 + 12 = 148$ coins in total.
Scoring
The solution will be tested on differently hard input data and the data is divided into groups as shown in the table below. The solution will then be scored according to how many groups are solved.
|
Group |
Points |
Constraints |
|
1 |
10 |
Only 10 kr coins |
|
2 |
30 |
Only 10 kr and 50 kr coins |
|
2 |
60 |
| Sample Input 1 | Sample Output 1 |
|---|---|
2 2 1 1 |
5 |
| Sample Input 2 | Sample Output 2 |
|---|---|
2 1 4 1 |
3 |
| Sample Input 3 | Sample Output 3 |
|---|---|
20 200 3 0 |
148 |
