POLICE
Problem
Over time, there have been many thefts and other incidents at universities, resulting in people wanting to increase security in these areas. For this reason, the government decided to establish the University Police. However, many members of the academic community, while agreeing that the areas need to be secured, believe that the solution chosen by the government is not the most appropriate. A few days before the arrival of the police at the Polytechnic University campus, you take on the difficult role of bridging the differences between the two sides. You are asked to write an algorithm that minimizes police presence at NTUA (National Technical University of Athens) while keeping it "safe".
The peripheral, circular road of the Polytechnic University campus has guard posts in specific positions, numbered from to . Due to the geometry of the road, if a police officer is placed at the -th guard post, they can see their own and the next guard posts in a clockwise direction. You are asked to calculate the minimum number of police officers that must be placed at the guard posts so that all guard posts are supervised by a police officer.
Input:
The first line of the input will contain a positive integer , the number of guard posts. The next line contains positive integers , the visibility of the -th guard post.
Output:
The output should contain one line with exactly one integer: the minimum number of police officers that must be placed so that all guard posts are supervised by someone.
Constraints
- Time Limit: sec.
- Memory Limit: MB.
Examples of Input - Output files:
1st
STDIN (police.in)
3
2 1 3
STDOUT (police.out)
1
Explanation of the first example
From guard post , a police officer can see all the guard posts.
2nd
STDIN (police.in)
4
1 1 1 2
STDOUT (police.out)
3
Explanation of the second example
We place a police officer at guard post and another at guard post , each of whom can only supervise their own guard post. Finally, we place a police officer at guard post , who will supervise guard posts and .
3d
STDIN (police.in)
8
1 5 1 4 3 2 1 5
STDOUT (police.out)
2
Notes
- For test cases with a total value of , it will be
- For test cases with a total value of , it will be and
- For test cases with a total value of , it will be
Comments