Jumping Robot
Time limit1sMemory limit512 MB
Find the minimum starting agility for a circular route where agility rises by 1 per jump, and name a platform that succeeds with it.
- Level
Medium6 of 10
- Topics
- Array, Sliding window
- Solved
- No attempts yet
Statement
Flatland Dynamics is developing a jumping robot. The robot is tested on a circular route of special platforms, numbered from 1 to . The distance between platform and platform is , and the distance between platform and platform 1 is .
The robot has an AI and learns to jump farther during the test. At any moment, the robot has an agility, which is an integer . The robot can jump from platform to platform if . Likewise, it can jump from platform to platform 1 if . After each jump, the robot's agility increases by 1.
The developers choose one platform as the starting point. The experiment succeeds if the robot can make jumps, going from each platform to the next, complete the full circle, and return to the starting platform.
The developers want to know the minimum initial agility that lets the experiment succeed, and which platform the robot should start from.
Input
The first line contains ().
The second line contains an integer that describes how the distance array is given.
If , the third line contains integers ().
If , the third line contains an integer () and three integers , , and (). The fourth line contains integers (). The distances are computed as follows.
If , then .
If , then . Here is the remainder of integer division, written as % in C++, Java, and Python.
Output
Print two integers. The first is the minimum initial agility . The second is the number of a starting platform from which the experiment succeeds with that agility.
If several starting platforms work, print any of them.
Hint
In the second example, the distance array is . The values from to are computed as follows.