The Circle
Time limit1sMemory limit128 MB
Choose n positive sector values (each at least k) so that consecutive circular block sums cover every integer from m to i, maximizing i.
- Level
Hard8 of 10
- Topics
- Brute force, Combinatorics, Math, Implementation
- Solved
- No attempts yet
Problem
A circle is divided into sectors (). You place one positive integer in each sector; every value must be at least .
A number is reachable if it equals the value of a single sector, or the sum of the values of two or more consecutive sectors along the circle. Because the sectors form a circle, a block of consecutive sectors may wrap around from the last sector back to the first. In total there are distinct blocks: the single sectors, the blocks of length , and the one whole circle.
Choose the sector values so that the reachable numbers contain every integer of the unbroken run , and make the largest value as large as possible.
For example, with , , the arrangement around the circle makes every integer from to reachable, so .
Input
Three integers , , and (, , ), given in this order and separated by whitespace or newlines.
It is guaranteed that , so the value is always reachable (place a sector equal to ).
Output
Print a single integer: the largest such that every integer from to inclusive is reachable.
Hint
Consider the example , , with the circular arrangement . Summing every block of consecutive sectors (wrapping around when needed) yields all integers from to :
- length 1:
- length 2:
- length 3:
- length 4:
- whole circle:
Every value in appears, so the answer for this case is .