#P10715. 【MX-X1-T3】「KDOI-05」简单的序列问题
【MX-X1-T3】「KDOI-05」简单的序列问题
Background
Original link: https://oier.team/problems/X1C.
Problem Description
Given a sequence of length . Define its prefix sum array . Define its value .
You may perform the following operation on sequence any number of times:
- Swap and , costing yuan, where is a given sequence.
For , find the minimum cost to make . If it is impossible, output .
Input Format
This problem contains multiple test cases.
The first line contains a positive integer , the number of test cases.
For each test case:
The first line contains a positive integer , the length of the sequence.
The second line contains positive integers, the sequence .
The third line contains positive integers, the sequence .
Output Format
For each test case:
Output one line with integers. The -th integer denotes the minimum cost to make . If it is impossible, output .
3
3
1 2 3
1 1 1
5
1 2 3 4 5
2 5 3 6 4
10
1 8 3 5 2 6 3 4 6 2
3 2 7 1 8 2 5 8 3 1
-1 2 0 -1
-1 -1 7 0 9 -1
-1 -1 5 3 4 0 7 8 6 -1 -1
Hint
[Sample Explanation]
For the first test case, initially , so the minimum cost to make is yuan.
Swapping and makes , so making can cost yuan. It can be proven that this is optimal.
It can be proven that there is no swapping plan that makes or .
[Constraints]
This problem uses bundled testdata.
| Subtask ID | Score | Special Property | ||
|---|---|---|---|---|
| None | ||||
| At most odd numbers in | ||||
| None | ||||
| None | ||||
For of the testdata: , , , .
Translated by ChatGPT 5