시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
---|---|---|---|---|---|
1 초 | 1024 MB | 26 | 22 | 19 | 82.609% |
There are $N$ members in the track club of JOI High School, numbered from $1$ to $N$. For the member $i$ ($1 ≤ i ≤ N$), the time of the 100 m sprint is $A_i$ msec, and the ability of controlling the baton is $B_i$.
The track club will participate in a national contest for the 300 m relay. Three members will run in the 300 m relay. Each member will run for 100 m. A runner will pass the baton to the next runner. Precisely, if the first runner is the member $i$ ($1 ≤ i ≤ N$), the second runner is the member $j$ ($1 ≤ j ≤ N$), and the third runner is the member $k$ ($1 ≤ k ≤ N$), then the three members will run the relay in the following steps.
Therefore, the record for the 300 m relay is $A_i + \max{(B_i , B_j)} + A_j + \max{(B_j , B_k)} + A_k$ msec. Here $\max{(x, y)}$ is the largest value of $x$ and $y$. Since you are the coach of the track club, you want to choose three distinct members for the relay and decide the order of the runners so that the record becomes minimum.
Write a program which, given information of the $N$ members of the track club, calculates the minimum possible record of the 300 m relay.
Read the following data from the standard input. Given values are all integers.
$N$
$A_1$ $B_1$
$A_2$ $B_2$
$\vdots$
$A_N$ $B_N$
Write one line to the standard output. The output should contain an integer which is the minimum possible record of the 300 m relay counted by msec.
번호 | 배점 | 제한 |
---|---|---|
1 | 25 | $N ≤ 100$. |
2 | 33 | $N ≤ 3\,000$. |
3 | 10 | $A_1 = A_2 = \cdots = A_N$. |
4 | 32 | No additional constraints. |
4 1070 90 1080 70 1050 60 1020 100
3320
If the first runner is the member 4, the second runner is the member 3, and the third runner is the member 2, then the time for the steps 1, 2, 3, 4, 5 of the relay will be 1020, 100, 1050, 70, 1080 msec, respectively. Thus, the record for the 300 m relay will be 1020 + 100 + 1050 + 70 + 1080 = 3320 msec. Since it is the minimum possible record, output 3320.
This sample input satisfies the constraints of Subtasks 1, 2, 4.
5 1000 28 1000 14 1000 21 1000 20 1000 14
3034
If the first runner is the member 2, the second runner is the member 5, and the third runner is the member 4, then the time for the steps 1, 2, 3, 4, 5 of the relay will be 1000, 14, 1000, 20, 1000 msec, respectively. Thus, the record for the 300 m relay will be 1000+14+1000+20+1000 = 3034 msec. Since it is the minimum possible record, output 3034.
This sample input satisfies the constraints of all the subtasks.
9 3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3
13
If the first runner is the member 1, the second runner is the member 2, and the third runner is the member 9, then the time for the steps 1, 2, 3, 4, 5 of the relay will be 3, 1, 4, 3, 2 msec, respectively. Thus, the record for the 300 m relay will be 3 + 1 + 4 + 3 + 2 = 13 msec. Since it is the minimum possible record, output 13.
This sample input satisfies the constraints of Subtasks 1, 2, 4.