#546
Unrated
Paired Up
시간 제한
2s
메모리 제한
1024MB
제출
0
정답
0
맞힌 사람
0
정답 비율
0.0%

문제

There are a total of NN (1N1051\le N\le 10^5) cows on the number line. The location of the ii-th cow is given by xix_i (0xi1090 \leq x_i \leq 10^9), and the weight of the ii-th cow is given by yiy_i (1yi1041 \leq y_i \leq 10^4).

At Farmer John's signal, some of the cows will form pairs such that

Every pair consists of two distinct cows aa and bb whose locations are within KK of each other (1K1091\le K\le 10^9); that is, xaxbK|x_a-x_b|\le K.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 T=1T=1, compute the minimum possible sum of weights of the unpaired cows.If T=2T=2, compute the maximum possible sum of weights of the unpaired cows.

입력

The first line of input contains TT, NN, and KK.

In each of the following NN lines, the ii-th contains xix_i and yiy_i. It is guaranteed that 0x1<x2<<xN1090\le x_1< x_2< \cdots< x_N\le 10^9.

출력

Please print out the minimum or maximum possible sum of weights of the unpaired cows.

예제 입력 1

2 5 2
1 2
3 2
4 2
5 1
7 2

예제 출력 1

6

예제 입력 2

1 5 2
1 2
3 2
4 2
5 1
7 2

예제 출력 2

2

예제 입력 3

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

예제 출력 3

2470

점수

Test cases 4-8 satisfy T=1T=1.Test cases 9-14 satisfy T=2T=2 and N5000N\le 5000.Test cases 15-20 satisfy T=2T=2.

코드 제출

코드를 제출하려면 로그인이 필요합니다.

로그인
내 제출
제출 내역이 없습니다.
맞은 사람
아직 맞은 사람이 없습니다.
난이도 투표
Unrated0명 투표
로그인 후 AC 받으면 투표할 수 있습니다.
전체 제출
제출 내역이 없습니다.