atcoder#AGC049C. [AGC049C] Robots
[AGC049C] Robots
Score : points
Problem Statement
There are robots on a number line. Specifically, for each , there is exactly one robot called Robot at coordinate .
We have many balls. Each of the balls has a positive integer written on it. Integer sequences and , each of length , describe these balls. Specifically, for each (), there are balls with written on them.
Now, Snuke will do the following sequence of operations:
- Step 1: Choose zero or more balls and replace the integers written on those balls with positive integers of his choice between and (inclusive). (The new integers can be chosen independently from each other.)
- Step 2: Eat the balls one by one in any order of his choice. Each time he eats a ball, he should do the following:
- Let be the integer written on the ball he has just eaten. If Robot exists, move it so that its coordinate decreases by . Here, if there is another robot at the destination, that robot (not Robot ) will be destroyed.
- Let be the integer written on the ball he has just eaten. If Robot exists, move it so that its coordinate decreases by . Here, if there is another robot at the destination, that robot (not Robot ) will be destroyed.
Snuke wants to eat all the balls without destroying Robot . Find the minimum number of balls Snuke must choose in Step 1 to achieve his objective.
Constraints
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
3
1 2 3
1 2 1
1
We can achieve the objective by choosing one ball with written on it, rewriting on it, and then eating the balls in the following order:
- Eat the ball with written on it, moving Robot from coordinate to coordinate and destroying Robot .
- Eat the ball with written on it, moving Robot from coordinate to coordinate .
- Eat the ball with written on it, moving Robot from coordinate to coordinate and destroying Robot .
- Eat the ball with written on it. Robot is already destroyed, so nothing happens.
4
1 3 5 7
3 1 4 1
0