#P9697. [GDCPC2023] Canvas
[GDCPC2023] 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 .