#P8465. 「REOI-1」调整圣剑
「REOI-1」调整圣剑
Background
William carried Xenoilius 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 Xenoilius to let the blade breathe.
William injected a little magic power. His temples hurt a bit, but this level was nothing serious.
Xenoilius immediately emitted a soft glow.
"— Adjustment begins."
Problem Description
Specifically, the holy sword Xenoilius consists of talismans, and each talisman has a weight . William 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, William has some restrictions when adjusting them. Each restriction is in the form , meaning that William 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, Ctholly wants to know what the minimum fatigue value is after William 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 William.
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