#5155. Problem 1. Paired Up
Problem 1. Paired Up
Problem 1. Paired Up
USACO 2021 December Contest, Gold
There are a total of () cows on the number line. The location of the -th cow is given by (), and the weight of the -th cow is given by ().
At Farmer John's signal, some of the cows will form pairs such that
- Every pair consists of two distinct cows and whose locations are within of each other (); that is, .
- Every cow is either part of a single pair or not part of a pair.
- The pairing is maximal; that is, no two unpaired cows can form a pair.
It's up to you to determine the range of possible sums of weights of the unpaired cows. Specifically,
- If , compute the minimum possible sum of weights of the unpaired cows.
- If , compute the maximum possible sum of weights of the unpaired cows.
INPUT FORMAT (input arrives from the terminal / stdin):
The first line of input contains , , and .
In each of the following lines, the -th contains and . It is guaranteed that .
OUTPUT FORMAT (print output to the terminal / stdout):
Please print out the minimum or maximum possible sum of weights of the unpaired cows.
SAMPLE INPUT:
2 5 2 1 2 3 2 4 2 5 1 7 2
SAMPLE OUTPUT:
6
In this example, cows and can pair up because they are at distance , which is at most . This pairing is maximal, because cows and are at distance , cows and are at distance , and cows and are at distance , all of which are more than . The sum of weights of unpaired cows is .
SAMPLE INPUT:
1 5 2 1 2 3 2 4 2 5 1 7 2
SAMPLE OUTPUT:
2
Here, cows and can pair up because they are at distance , and cows and can pair up because they are at distance . This pairing is maximal because only cow remains. The weight of the only unpaired cow here is simply .
SAMPLE INPUT:
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
SAMPLE OUTPUT:
2470
The answer for this example is .
SCORING: Test cases 4-8 satisfy .Test cases 9-14 satisfy and .Test cases 15-20 satisfy .
Problem credits: Benjamin Qi