#STK0000085. Cây nhiễm độc (Poisonous Plants)
Cây nhiễm độc (Poisonous Plants)
Poisonous Plants
Source: HackerRank
Version: Phuoc Hung OJ Extended
Problem Statement
There are plants from left to right, where plant has pesticide level . After each day, every plant whose pesticide level is greater than that of the currently alive plant immediately to its left dies simultaneously. The process repeats on the surviving sequence. Determine the number of days until no plant dies.
Input
The first line contains . The second line contains integers .
Output
Print the number of days until no more plants die.
Subtasks
- Subtask 1 (30 points): ; all other conditions are unchanged.
- Subtask 2 (70 points): , .
Examples
Input
7
6 5 8 4 7 10 9
Output
2
Explanation
Initially the pesticide levels are .
On day , each plant is compared with the alive plant immediately to its left using the state at the start of the day:
- , so the plant with level dies;
- , so the plant with level dies;
- , so the plant with level dies.
After day , the surviving sequence is .
On day , the plant with level is immediately to the right of level , and , so it dies. The survivors are .
Now , so no surviving plant has more pesticide than its left neighbor. The process stops after days, hence the output is 2.