Marica
Time limit1sMemory limit512 MB
Pick target counts for baskets so every value in [A,B] appears, minimizing total plum additions and removals.
- Level
Medium6 of 10
- Topics
- Greedy, Sorting, Implementation
- Solved
- No attempts yet
Problem
Marica's grandmother keeps a large orchard and carries plums to the market every morning. This morning Marica filled baskets with plums for her, but grandmother stayed out late last night and is still asleep, so Marica wants to fool around a little longer. She will eat some of the plums from the baskets and pick more plums in the orchard.
Marica wants every natural number in the interval to be the exact number of plums in at least one basket. Both endpoints and belong to the interval. Given how many plums each basket holds right now, find the smallest number of operations Marica needs to reach her goal. One operation is one of the following.
- Eat one plum from some basket.
- Pick one plum in the orchard and put it into some basket.
Input
The first line contains the number of baskets . ()
The second line contains two natural numbers and . (, )
The -th of the next lines contains , the number of plums in basket . ()
Output
Print the smallest number of operations on the first line.