#P9697. [GDCPC 2023] Canvas
[GDCPC 2023] Canvas
题目描述
There is a sequence of length . At the beginning, all elements in the sequence equal to . There are also operations, where the -th operation will change the value of the -th element in the sequence to , and also change the value of the -th element in the sequence to . Each operation must be performed exactly once.
Find the optimal order to perform the operations, so that after all operations, the sum of all elements in the sequence is maximized.
输入格式
There are multiple test cases. The first line of the input contains an integer indicating the number of test cases. For each test case:
The first line contains two integers and () indicating the length of the sequence and the number of operations.
For the following lines, the -th line contains four integers , , and (, ) indicating the -th operation.
It's guaranteed that neither the sum of nor the sum of of all test cases will exceed .
输出格式
For each test case, first output one line containing one integer, indicating the maximum sum of all elements in the sequence after all operations. Then output another line containing integers separated by a space, indicating the optimal order to perform the operations, where is the index of the -th operation to be performed. Each integer from to (both inclusive) must appear exactly once. If there are multiple valid answers, you can output any of them.
2
4 4
1 1 2 2
3 2 4 1
1 2 3 2
2 1 4 1
4 2
3 2 4 1
1 2 3 1
7
4 1 3 2
5
2 1
提示
For the first sample test case, after performing operations in order, the sequence becomes . The sum of all elements is .
For the second sample test case, after performing operations in order, the sequence becomes . The sum of all elements is .