#USACOC2211B. Paired Up
Paired Up
Description
There are a total of cows on the number line, each ofwhich is a Holstein or a Guernsey. The breed of the -th cow is given by , 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 a Holstein and a Guernsey whose locations arewithin 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 apair.
It's up to you to determine the range of possible sums of weights of theunpaired cows. Specifically,
- If , compute the minimum possible sum of weights of the unpairedcows.
- If , compute the maximum possible sum of weights of theunpaired cows.
Input Format
The first input line contains , , and .
Following this are lines, the -th of which contains . It isguaranteed that .
Output Format
The minimum or maximum possible sum of weights of the unpaired cows.
2 5 4
G 1 1
H 3 4
G 4 2
H 6 6
H 8 9
2 5 4
G 1 1
H 3 4
G 4 2
H 6 6
H 8 9
Cows and can pair up because they are at distance , which is at most. This pairing is maximal, because cow , the only remaining Guernsey,is at distance from cow and distance from cow , which are morethan . The sum of weights of unpaired cows is.
1 5 4
G 1 1
H 3 4
G 4 2
H 6 6
H 8 9
1 5 4
G 1 1
H 3 4
G 4 2
H 6 6
H 8 9
Cows and can pair up because they are at distance , andcows and can pair up because they are at distance . Thispairing is maximal because only cow remains. The sum of weights ofunpaired cows is the weight of the only unpaired cow, which is simply .
2 10 76
H 1 18
H 18 465
H 25 278
H 30 291
H 36 202
G 45 96
G 60 375
G 93 941
G 96 870
G 98 540
2 10 76
H 1 18
H 18 465
H 25 278
H 30 291
H 36 202
G 45 96
G 60 375
G 93 941
G 96 870
G 98 540
Scoring
- Test cases 4-7 satisfy .
- Test cases 8-14 satisfy and .
- Test cases 15-22 satisfy .
Note: the memory limit for this problem is 512MB, twice the default.
Problem Credit
Problem credits: Benjamin Qi