Editorial for COCI '10 Contest 5 #1 Gljive
Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.
Submitting an official solution before solving the problem yourself is a bannable offence.
Notice that distance between the numbers and is equal to:
- , if is greater than
- , otherwise
We add numbers one by one starting from the first. If the running sum becomes greater than , our solution is either the previous sum we had, or the current sum. We choose the sum closer to .
If the sum of all the numbers is not greater than , we output this sum.
Comments