Paired Up
시간 제한: 2000ms메모리 제한: 1024MB출처: USACO 2021 December PlatinumBOJ 23870
문제
There are a total of () cows on the number line, each of which 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 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.
입력
The first input line contains , , and .
Following this are lines, the -th of which contains . It is guaranteed that .
출력
The minimum or maximum possible sum of weights of the unpaired cows.
예제
예제 1
입력
2 5 4 G 1 1 H 3 4 G 4 2 H 6 6 H 8 9
출력
16
예제 2
입력
1 5 4 G 1 1 H 3 4 G 4 2 H 6 6 H 8 9
출력
6
예제 3
입력
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
출력
1893
코드를 제출하려면 로그인하세요.