#P3103. [USACO14FEB] Airplane Broading G
[USACO14FEB] Airplane Broading G
题目描述
FJ's cows have decided to take a vacation, and have miraculously managed to find an airline willing to sell them tickets. When they arrive at the airport and start boarding their plane, they face an interesting problem, however.
The airplane has seats, which we model as the points through on the number line. All N cows are standing in line waiting to get to their seats. Cow is at position , Cow is at position , and so on. Cow i has been assigned to Seat , where ,..., is a permutation of ,...,.
At each time step, each cow takes a step to the right if she can. When cow reaches her seat , she will stop to put her baggage in the overhead bin, which takes seconds, and then sit down. For those steps, the cow behind her (if there is one) is blocked from moving forward. If there is a line of cows behind her, the line is effectively blocked as well.
How long will it take for all the cows to sit down?
The sum of for all cows will be less than .
输入格式
-
Line : A single integer, .
-
Lines ..: Two space-separated integers, and .
输出格式
- Line : A single line indicating the amount of time it takes to seat all cows.
3
2 5
3 10
1 5
19
提示
Initially, the cows are situated like this:
cows ->
<- seats
with cow trying to get to seat , cow trying to get to seat , and cow trying to get to seat .
After one step, they will all move to the right and cow will reach her seat:
123 123 Cow takes seconds to sit down, at which point she effectively disappears.
12 123 It takes more seconds for cows and to reach their desired seats:
12 123 It takes seconds for cow to sit down and seconds for cow to sit down, so that's seconds total.
In total this took seconds.