#P9693. [GDCPC 2023] New Houses
[GDCPC 2023] New Houses
题目描述
With the construction and development of Guangdong, more and more people choose to come to Guangdong to start a new life. In a recently built community, there will be people moving into houses which are arranged in a row. The houses are numbered from to (both inclusive). House and are neighboring houses, if and only if . We need to assign each person to a house so that no two people will move into the same house. If two people move into a pair of neighboring houses, they will become neighbors of each other.
Some people like to have neighbors while some don't. For the -th person, if he has at least one neighbor, his happiness will be ; Otherwise if he does not have any neighbor, his happiness will be .
As the planner of this community, you need to maximize the total happiness.
输入格式
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 number of people and the number of houses.
For the following lines, the -th line contains two integers and () indicating the happiness of the -th person with and without neighbors.
It's guaranteed that the sum of of all test cases will not exceed .
输出格式
For each test case output one line containing one integer indicating the maximum total happiness.
3
4 5
1 100
100 1
100 1
100 1
2 2
1 10
1 10
2 3
100 50
1 1000
400
2
1050
提示
For the first sample test case, the optimal strategy is to let person move into house and let person to move into house to . Thus, person have no neighbors while person to have neighbors. The answer is . Of course, we can also let person to move into house to and let person move into house . This will also give us total happiness.
For the second sample test case, as there are only houses, person and have to be neighbors. The answer is .
For the third sample test case, the optimal strategy is to let person move into house and let person move into house . Thus, both of them have no neighbors. The answer is .