#P7987. [USACO21DEC] Paired Up G
[USACO21DEC] Paired Up G
Problem Description
There are a total of () cows on a number line. The position of the -th cow is (), and the weight of the -th cow is ().
According to Farmer John’s signal, some cows will form pairs such that:
-
Each pair contains two different cows and whose positions differ by at most (); that is, .
-
Each cow is either included in exactly one pair or does not belong to any pair.
-
The pairing is maximal; that is, no two unpaired cows can form a pair.
You need to find the possible range of the total weight of unpaired cows. Specifically:
-
If , compute the minimum possible total weight of unpaired cows.
-
If , compute the maximum possible total weight of unpaired cows.
Input Format
The first line contains , , and .
The following lines each contain and . The input guarantees that .
Output Format
Output the minimum or maximum possible total weight of unpaired cows.
2 5 2
1 2
3 2
4 2
5 1
7 2
6
1 5 2
1 2
3 2
4 2
5 1
7 2
2
2 15 7
3 693
10 196
12 182
14 22
15 587
31 773
38 458
39 58
40 583
41 992
84 565
86 897
92 197
96 146
99 785
2470
Hint
Sample Explanation 1
In this example, cows and can be paired because their distance is , which does not exceed . This pairing is maximal because the distance between cows and is , the distance between cows and is , and the distance between cows and is , all greater than . The total weight of unpaired cows is .
Sample Explanation 2
Here, cows and can be paired because their distance is , and cows and can be paired because their distance is . This pairing is maximal because only cow remains. The total weight of unpaired cows is .
Sample Explanation 3
The answer for this example is .
Constraints
- Test cases 4–8 satisfy .
- Test cases 9–14 satisfy and .
- Test cases 15–20 satisfy .
Translated by ChatGPT 5