#P16276. [蓝桥杯 2026 省 C] 回收处理
[蓝桥杯 2026 省 C] 回收处理
Problem Description
On the conveyor line of an automated factory, there are parts arranged in order. Each part has a marked price : if it is recycled, this price is counted as revenue; if it is processed, this price is counted as cost.
As the person in charge of the factory area, Xiao Lan needs to choose two specific groups from these parts:
- Recycling group: choose exactly parts to recycle, with total revenue denoted by .
- Processing group: choose exactly parts to process, with total cost denoted by .
Because the conveyor line is irreversible and moves in only one direction, the selection must follow a strict order: every recycled part must appear earlier than all processed parts in the original sequence (that is, if the indices of recycled parts are and the indices of processed parts are , then it must hold that ).
Under this order constraint, the remaining parts on the line will be discarded directly, producing no revenue or cost.
Now Xiao Lan wants to find a plan that makes the total recycling revenue minus the total processing cost () as large as possible. Please compute the maximum possible value of this difference.
Input Format
The first line contains an integer , representing the number of parts to be selected in each group.
The second line contains integers , representing the marked prices of the parts on the line from left to right.
Output Format
Output one integer, representing the maximum possible value of under all constraints.
2
1 10 5 1 2 1
13
Hint
Sample Explanation
The optimal plan is: recycle the nd and rd parts, and process the th and th parts. Then , , and .
Constraints
For of the testdata, .
For all testdata, , .
Translated by ChatGPT 5