Paired Up

아직 제출이 없습니다시간 제한2초메모리 제한1024 MB

문제

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 x_ix\_i (0x_i1090 \leq x\_i \leq 10^9), and the weight of the ii-th cow is given by y_iy\_i (1y_i1041 \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, x_ax_bK|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 x_ix\_i and y_iy\_i. It is guaranteed that 0x_1<x_2<<x_N1090\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.