Sugar Delivery 2
InterviewTime limit0.25sMemory limit1024 MB
Find the fewest 3-kg and 5-kg bags that add up to exactly N kilograms, or report -1 if no combination works.
Problem
Sanggeun delivers sugar from a sugar factory these days. He must deliver exactly kilograms of sugar to a candy shop. The factory packs its sugar in bags. There are 3-kilogram bags and 5-kilogram bags.
Sanggeun is lazy, so he wants to carry as few bags as possible. For example, when he must deliver 18 kilograms of sugar, he could take six 3-kilogram bags. If he delivers three 5-kilogram bags and one 3-kilogram bag instead, he can deliver with fewer bags.
Input
The first line contains . ()
Output
Print the minimum number of bags Sanggeun delivers. If it is impossible to deliver exactly kilograms, print -1.