#P16956. 「NLOI Round1」真空剑圣
「NLOI Round1」真空剑圣
Problem Description
N God is a farmer who grows vegetables. He planted flowers, and each flower has an initial beauty value . However, he found that 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 -th weed grows between the -th flower and the -th flower, with beauty value . 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 -th flower become . Or he can trim it to the right, making the beauty value of the -th flower become . Now, he wants to know the maximum possible sum of the flowers' beauty values after trimming.
Formally: Given a sequence of length , there are operations. For each operation, two parameters are given. You can skip this operation, or choose to perform one of the following assignments:
-
Assign to .
-
Assign to .
Find the maximum possible sum of the sequence elements after the operations.
Input Format
The first line contains two integers .
The second line contains integers, representing the sequence .
The next lines each contain two integers .
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 to . In the second trimming, trim the left flower and assign to . The third operation is skipped. The sum of is , and it can be proven that this is the optimal plan.
For all testdata, , , .
Constraints table:
| Data Point ID | Score | Special Property | ||
|---|---|---|---|---|
| None | ||||
| A | ||||
| B | ||||
| None | ||||
Special Property A: . For the -th operation among the operations, .
Special Property B: .
Translated by ChatGPT 5