#P10412. 「QFOI R2」钟声远带斜阳
「QFOI R2」钟声远带斜阳
Problem Description
Note: In this problem, all sequence indices start from .
Little R is a lovely girl who likes studying infinite sequences.
She calls an infinite sequence wonderful if and only if there exists a natural number such that for all , the sum of all numbers in with indices in the interval is non-negative (that is, ). For example, the sequence is wonderful, taking works; but is not wonderful.
She currently only has a finite sequence of length , and she can perform the following three operations any number of times:
- Pay cost , choose an integer (), and increase by .
- Pay cost , choose an integer (), delete , and update to be the new length of the sequence. You cannot delete the sequence until it becomes empty.
- Pay cost , choose two integers (), and swap and .
She hopes that after some operations, by concatenating infinitely many copies of the finite sequence in order, she obtains an infinite sequence (i.e., ), such that is wonderful. Please find the minimum total cost.
Input Format
The first line contains four integers .
The second line contains integers, representing the sequence .
Output Format
One line with one integer, representing the minimum cost.
5 1 2 5
2 -2 3 -3 -1
1
5 2 1 5
2 -2 3 -3 -1
1
5 1 1 1
0 1 2 3 4
0
Hint
Explanation of Sample
Pay cost to increase by , obtaining the sequence , which is wonderful. Taking satisfies the requirement.
It can be proven that no solution with a smaller cost exists.
Explanation of Sample
Pay cost to delete , obtaining the sequence , which is wonderful. Taking satisfies the requirement.
It can be proven that no solution with a smaller cost exists.
Constraints
This problem uses bundled testdata. Only by passing all test points of a subtask and all the subtasks it depends on can you get the corresponding score.
For all testdata: , , .
- Subtask 1 ( points): .
- Subtask 2 ( points): . Depends on Subtask 1.
- Subtask 3 ( points): .
- Subtask 4 ( points): . Depends on Subtask 3.
- Subtask 5 ( points): No special restrictions. Depends on Subtasks 1, 2, 3, and 4.
Translated by ChatGPT 5