Paired Up
시간 제한2초메모리 제한1024 MB
정렬된 소들의 위치와 무게가 주어질 때, 거리가 K 이내인 소들끼리 짝지어 최대로 짝을 이룰 때 남는 소들의 무게 합의 최솟값 또는 최댓값을 구한다.
문제
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.
입력
The first line of input contains , , and .
In each of the following lines, the -th contains and . It is guaranteed that .
출력
Please print out the minimum or maximum possible sum of weights of the unpaired cows.