#P13509. [OOI 2024] Almost Certainly
[OOI 2024] Almost Certainly
题目描述
Let's say that two multisets are equal if they are equal up to one element. That is, it should be possible to change at most one element in the first multiset so that they become equal. For example, the multisets and are equal , and are equal , and and are not equal .
A boy named Vasya really liked this definition and immediately came up with a problem about it.
Vasya has two arrays and , where for all from to . Vasya can apply the following operation to array as many times as he wants (possibly zero times): choose any index () and subtract 1 from . At the same time, Vasya does not change array .
Vasya quickly understood what sequence of operations is needed to make the multiset of values of arrays and equal . Therefore, Vasya made the task more complicated --- now for each prefix of these arrays, he wants to know the minimum number of operations needed to make the prefixes of the arrays equal .
More formally, for each from to , Vasya wants to take the elements , as well as the elements . Vasya wants to know the minimum number of operations needed to make the multisets of these elements equal . Note that the task for each is solved .
输入格式
Each test consists of one or more sets of input data. The first line contains a single integer () --- the number of sets of input data. Then follows the description of the sets of input data.
The first line of each set of input data contains a single integer () --- the size of arrays and .
The second line of each set of input data contains integers () --- the elements of array .
The third line of each set of input data contains integers () --- the elements of array .
Let be the sum of for all sets of input data in one test. It is guaranteed that .
输出格式
For each set of input data, output integers, each of which is the answer to the task for each possible prefix length. It can be shown that the answer always exists.
4
2
3 4
1 2
2
3 4
1 3
3
11 17 14
1 13 10
4
100 11 50 42
30 1 20 5
0 1
0 0
0 4 2
0 10 30 48
3
4
2 4 5 12
1 3 4 10
4
3 5 8 20
1 2 6 7
4
4 4 4 4
1 2 3 4
0 1 1 3
0 1 3 6
0 2 3 3
提示
Note
Consider the first set of input data in the first example.
- For a prefix of length , nothing needs to be done.
- For a prefix of length , needs to be decreased by 1 once, after which will be equal to , will be equal to , and they will be equal .
Consider the third set of input data in the first example.
- For a prefix of length , nothing needs to be done.
- For a prefix of length , needs to be decreased by 4 times, after which the prefix of will be equal to , the prefix of will be equal to , and they will be equal .
- For a prefix of length , needs to be decreased by 1 and needs to be decreased by 1, after which will be equal to , will be equal to , and they will be equal .
Scoring
The tests for this problem consist of six groups. Points for each group are given only if all tests of the group and all tests of the required groups are passed. Please note that passing the example tests is not required for some groups. means that the results of testing your solution on this group will only be available after the end of the competition.
Group | Points | Additional constraints | Required groups | Comment |
---|---|---|---|---|
0 | -- | Examples. | ||
1 | 16 | 0 | -- | |
2 | 13 | 0, 1 | ||
3 | 24 | 0--2 | ||
4 | 13 | -- | -- | |
5 | 14 | 4 | ||
6 | 20 | 0--5 | Offline-evaluation. |