luogu#P8465. 「REOI-1」调整圣剑
「REOI-1」调整圣剑
Background
Willem carried Seniorious out of the warehouse.
On a slightly raised hill at the edge of Floating Island No. 68.
It was a night with steady wind, clear air, gentle starlight, and all conditions were suitable.
He lifted the cloth covering Seniorious to let the blade breathe.
Willem injected a little magic power. His temples hurt a bit, but this level was nothing serious.
Seniorious immediately emitted a soft glow.
"— Adjustment begins."
Problem Description
Specifically, the holy sword Seniorious consists of talismans, and each talisman has a weight . Willem will perform adjustments. In each adjustment, he adjusts one talisman and gains a fatigue value equal to the talisman's weight.
However, due to some strange connection between the talismans, Willem has some restrictions when adjusting them. Each restriction is in the form , meaning that Willem must either adjust one of the first talismans in the -th adjustment or adjust one of the last talismans in the -th adjustment, otherwise the holy sword will collapse.
Now, Chtholly wants to know what the minimum fatigue value is after Willem finishes all adjustments.
Note that each talisman can be adjusted more than once.
Input Format
The first line contains three positive integers .
The next line contains positive integers .
The next lines each contain positive integers .
Output Format
Output one number, the minimum possible total fatigue value of Willem.
3 2 1
2 1 3
1 2 2 2
2
3 2 1
2 1 3
1 2 1 1
3
10 4 2
5 2 1 3 3 1 4 5 5 3
4 3 1 7
2 4 5 5
4
Hint
Sample explanation:
For the first sample, choose in the first adjustment and choose in the second adjustment. It can be proven that this is the minimum value that satisfies the restrictions.
For the second sample, choosing in the first adjustment and choosing in the second adjustment is the minimum value to satisfy the restrictions.
Constraints:
For of the testdata: , .
For of the testdata: , .
For of the testdata: , .
For of the testdata: , , .
For each restriction: , .
Translated by ChatGPT 5