| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 2 초 | 2048 MB | 12 | 12 | 12 | 100.000% |
You are the leader of a swarm of $n$ sharks living in a one-dimensional ocean. The sharks are positioned from left to right, with each adjacent pair separated by a distance of one unit.
As the leader, you want all the sharks to gather at a common point to form a single group. Initially, no two sharks belong to the same group; for each $i = 1, \dots , n,ドル the $i$-th shark from the left forms its own group, uniquely numbered $a_i,ドル consisting of only itself.
To achieve your goal, you can command the sharks to perform the following actions $n − 1$ times.
All sharks move at a constant speed of one unit distance per unit time. Commands must be executed sequentially, with no overlap in execution. Once a command is completed, the next one can begin immediately.
Compute the minimum time required for all the sharks to gather at a common point by commanding the sharks $n − 1$ times optimally.
The first line of input contains an integer $n$ (2ドル ≤ n ≤ 500$). The second line contains $n$ pairwise distinct integers $a_1, a_2, \dots , a_n$ (1ドル ≤ a_i ≤ n$).
Output the minimum time required for all the sharks to gather at a common point.
4 3 2 4 1
4
You can command the sharks to perform the following actions:
The total time is 1ドル + 1 + 2 = 4$. It can be shown that 4ドル$ units of time is optimal.
9 1 2 4 5 7 8 3 6 9
17