#K71422. Castle Capture
Castle Capture
Castle Capture
You are tasked with calculating the number of days required to capture a series of castles. The castles are arranged in a line, and each castle has a defense level represented by an integer. You start with an attack power of 1 and attempt to capture each castle in order.
For each castle, if your current attack power is less than the castle's defense level, you must wait enough days to increase your power to match that defense level. Once your attack power is at least equal to the castle's defense level, you capture the castle in one day and your attack power increases by 1.
Determine the total number of days required to capture all the castles.
inputFormat
The input is given via standard input (stdin
) and consists of two lines:
- The first line contains an integer n, representing the number of castles.
- The second line contains n space-separated integers, where the i^{th} integer represents the defense level of the i^{th} castle.
outputFormat
Output a single integer to standard output (stdout
), representing the total number of days required to capture all the castles.
3
1 2 3
3