#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 nn talismans, and each talisman has a weight aia_i. William will perform kk 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 (i,j,x,y)(i,j,x,y), meaning that William must either adjust one of the first xx talismans in the ii-th adjustment or adjust one of the last yy talismans in the jj-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 n,k,qn, k, q.

The next line contains nn positive integers a1,a2,a3...ana_1, a_2, a_3...a_n.

The next qq lines each contain 44 positive integers i,j,x,yi, j, x, y.

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 a2a_2 in the first adjustment and choose a2a_2 in the second adjustment. It can be proven that this is the minimum value that satisfies the restrictions.

For the second sample, choosing a1a_1 in the first adjustment and choosing a2a_2 in the second adjustment is the minimum value to satisfy the restrictions.

Constraints:

For 24%24\% of the testdata: 1n201 \le n \le 20, 1k,q141 \le k, q \le 14.

For 56%56\% of the testdata: 1n1001 \le n \le 100, 1k,q601 \le k, q \le 60.

For 80%80\% of the testdata: 1n1051 \le n \le 10^5, 1k,q1031 \le k, q \le 10^3.

For 100%100\% of the testdata: 1n1051 \le n \le 10^5, 1k,q1041 \le k, q \le 10^4, 1ai1051 \le a_i \le 10^5.

For each restriction: 1i,jk1 \le i, j \le k, 1x,yn1 \le x, y \le n.

Translated by ChatGPT 5