#P16956. 「NLOI Round1」真空剑圣

    ID: 18730 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 显示难度普及+/提高− 上传者: 标签>动态规划 DP洛谷原创O2优化洛谷月赛线性 DP

「NLOI Round1」真空剑圣

Problem Description

N God is a farmer who grows vegetables. He planted nn flowers, and each flower has an initial beauty value aia_i. However, he found that mm weeds also grew in the garden, so N God decided to trim these weeds to make the flowers more beautiful.

It is known that the ii-th weed grows between the xix_i-th flower and the (xi+1)(x_i+1)-th flower, with beauty value yiy_i. N God can choose to trim this weed, or not trim it. If he chooses to trim it, he can trim it to the left, making the beauty value of the xix_i-th flower become yiy_i. Or he can trim it to the right, making the beauty value of the (xi+1)(x_i+1)-th flower become yiy_i. Now, he wants to know the maximum possible sum of the flowers' beauty values after trimming.

Formally: Given a sequence aa of length nn, there are mm operations. For each operation, two parameters xi,yix_i, y_i are given. You can skip this operation, or choose to perform one of the following assignments:

  • Assign axia_{x_i} to yiy_i.

  • Assign axi+1a_{x_i+1} to yiy_i.

Find the maximum possible sum of the sequence elements after the mm operations.

Input Format

The first line contains two integers n,mn, m.

The second line contains nn integers, representing the sequence aa.

The next mm lines each contain two integers xi,yix_i, y_i.

Output Format

Output one integer, representing the maximum possible sum of the flowers' beauty values after trimming.

3 3
2 1 4
1 3
2 4
1 1
11
5 8
3 1 5 2 3
1 2
1 4
2 5
2 4
3 7
3 6
4 4
4 10
32
12 9
1 1 1 2 1 1 1 1 1 2 2 1
1 2
1 2
2 2
5 2
5 2
6 1
8 2
8 2
10 2
22
7 15
1 7 14 1 9 4 18
1 10
3 6
2 6
3 20
2 12
5 16
4 7
3 17
2 6
1 23
2 12
4 16
3 14
5 12
5 20
126

Hint

Explanation for Sample 1: In the first trimming, trim the left flower and assign a1a_1 to 33. In the second trimming, trim the left flower and assign a2a_2 to 44. The third operation is skipped. The sum of aa is 3+4+4=113+4+4=11, and it can be proven that this is the optimal plan.

For all testdata, 1≤ai,yi≤2000,1≤xi<n1\leq a_i,y_i\leq 2000, 1 \le x_i< n, 2≤n≤2×1052 \leq n\leq2\times 10^5, 1≤m≤1061 \leq m\leq10^6.

Constraints table:

Data Point ID Score n≤n\leq m≤m\leq Special Property
11 1616 2×1052\times 10^5 2020 None
22 2020 10610^6
33 1212 5050 100100
44 2424 2×1052\times 10^5 10610^6 A
55 2020 B
66 88 None

Special Property A: m=2n−2m=2n-2. For the ii-th operation among the mm operations, xi=⌈i2⌉x_i=\lceil \frac{i}{2}\rceil.

Special Property B: ai,yi≤2a_i,y_i\leq 2.

Translated by ChatGPT 5