시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
---|---|---|---|---|---|
2 초 | 512 MB | 36 | 3 | 3 | 30.000% |
Boyan is playing a computer game. In the beginning there are N balls arranged in a line. Each ball has a number written on it, so that every two consecutive balls have different numbers. The game consists of the following steps:
The score is the number of balls that are automatically removed. The goal of the game is to maximize the score.
Let’s see an example of a game with 6 balls with numbers {1, 2, 3, 2, 1, 5}.
The number of balls that are automatically removed is 4. It is the maximum possible score for this game. Boyan is playing a lot, but he is still not sure when he is playing optimally. Write program game to help him to find the best score he can achieve.
The first line contains the positive integer N.
The second line contains N positive integers ─ the numbers written on the balls.
Print the maximum possible score Boyan can achieve.
6 1 2 3 2 1 5
4
9 1 5 1 3 2 4 2 3 1
6
Remove the 9th, 6th and 2nd ball.
Olympiad > International Autumn Tournament in Informatics > 2017 > Group B (Juniors) 1-2번