Coin change
Time limit2sMemory limit512 MB
Find the fewest 2 won and 5 won coins that sum to n, or report -1 when no combination works.
- Level
Easy3 of 10
- Topics
- Greedy, Math, Brute force
- Solved
- No attempts yet
Problem
Chunhyang works at the counter of a convenience store.
A customer asks for change in 2 won coins and 5 won coins only. Both kinds of coins are available without limit. The change has to be paid with as few coins as possible. Given the amount of change , write a program that reports the minimum number of coins.
For example, change of 15 won is paid with three 5 won coins, so 3 coins in total. Change of 14 won is paid with two 5 won coins and two 2 won coins, so 4 coins. Change of 13 won is paid with one 5 won coin and four 2 won coins, so 5 coins.
Input
The first line contains the amount of change ().
Output
Print the minimum number of coins on the first line. If the amount cannot be paid with 2 won and 5 won coins, print -1.