| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 2 초 | 1024 MB | 30 | 13 | 13 | 46.429% |
You are given an integer sequence $A$ of length 2ドルQ-1$ and $Q$ intervals $[L_i, R_i)$. Here, $L_i,ドル $R_i$ satisfy $L_i < R_i,ドル and each integer between 1ドル$ and 2ドルQ$ appears once as an end of an interval.
Your goal is to create a set $S$ of intervals to satisfy at least one of the following conditions for all $i = 1, 2, \dots, Q$.
The cost of the set $S$ is defined as follows.
The sum of $A_l + A_{l+1} + \dots + A_{r-1}$ for all intervals $[l,r)$ included in $S$.
Find the minimum cost of the set that satisfies the condition.
$Q$
$L_1$ $R_1$
$\vdots$
$L_Q$ $R_Q$
$A_1$ $A_2$ $\dots$ $A_{2Q-1}$
Output the minimum cost of the set that satisfies the condition. Add a new line at the end of the output.
3 1 4 2 5 3 6 1 2 3 4 5
20
5 3 7 1 10 5 9 4 8 2 6 6 4 8 5 9 8 9 8 2
132
In Sample Input 1, the optimal set is $S = \{[1, 4), [2, 3), [3, 5), [5, 6)\},ドル where the cost is $y + 2+7+5=20$.