Babushka and her pierogi
시간 제한6초메모리 제한1024 MB
각 접시의 현재 값과 목표 값이 주어질 때, 값 x와 y를 맞바꾸는 비용이 |x-y|+C일 때 모든 접시를 목표 값으로 만드는 최소 비용 교환 순서를 찾는다.
문제
Babushka Bajtmiła is throwing a party! And the main dish served will be her famous pierogi.
There will be plates available during the party, and Babushka plans to put exactly pierogi on the -th plate (all the values are distinct). Though the task seemed too heavy for an old lady, Bajtmiła has stood up to the challenge and almost instantly prepared all of the pierogi needed, divided among plates with pierogi. Next, Bajtmiła has distributed the plates among the plates. However, she soon realized that while she got the numbers right, she messed up the order of the plates.
Bajtmiła is quite tired and is only willing to perform one type of operation: she can choose two plates numbered and , and swap the amounts of pierogi on each plate. In other words, if there are pierogi at the plate , and pierogi at the plate , then after this operation there will be pierogi at the plate , and pierogi at plate . Such an operation takes exactly seconds to perform -- seconds for finding a proper spoon, and second for each of pierogi moved.
The party is about to start very soon! Now, Bajtmiła won't allow you to touch anything in the kitchen, but she has put her trust in your algorithmic skills. She asked you to find a sequence of operations restoring the desired order of numbers, and must do it in the shortest time possible. Can you help Bajtmiła?
입력
The first line of input contains the number of test cases (). The descriptions of the test cases follow.
The first line of each test case consists of two numbers and () with their meaning described in the statement above.
Next lines describe consecutive plates. The -th line contains two numbers and () indicating the current and the desired amount of pierogi on -th plate respectively.
In each test case, numbers are distinct. Furthermore, the sets and are the same.
The sum over values in all test cases does not exceed .
출력
For each test case, your output must match the following description:
In the first line, print two integers and -- the total time and the number of operations in your solution respectively.
Next lines of your output should describe your solution. In the -th line print two numbers and , indicating that the -th operation in your solution swaps the amounts of pierogi at -th and -th plate.
After all operations from your solution, the -th plate must contain exactly pierogi.
힌트
A sequence should become the sequence . We first perform the operation on the first two plates, obtaining the sequence at the cost . The second and final operation swaps the pierogis from the first and fourth plate, achieving the desired sequence . The cost of this operation is , and the total cost is , which is the minimal possible.