Cities Robbery

Time limit: 1000 ms
Memory limit: 128 MB

There are NN cities placed in a line. For each city ii you know its coodinate xix_i and the amount of money wiw_i its citizens have.

You are a robber and you have a car intially placed at coordinate XX. The car has enough gas to last you for KK kilometers (each kilometer is represented as a unit on the axis). When you pass through a city you steal all the money of its citizens.

What is the maximum total amount you can steal? You can change direction as you wish, but you can't rob the same city twice.

Standard input

The first line contains three integers NN, XX, and KK.

Each of the next NN lines contains two integers xx and ww representing the coordinate of a city and the amount of money its citizens have.

Standard output

Print a single integer representing the total amount you can steal.

Constraints and notes

  • 1N1051 \leq N \leq 10^5
  • 106xi,X106-10^6 \leq x_i, X\leq 10^6
  • 0K1090 \leq K \leq 10^9
  • 1wi1091 \leq w_i \leq 10^9
  • The coordinates of the cities are distinct.
  • There is no city at your starting point XX.

InputOutput
4 0 3
-4 10
-1 1
1 1
4 10
2
4 0 4
-4 10
-1 1
1 1
4 10
11
4 3 7
0 9
4 1
5 5
7 8
15

Authenticate to use the workspace

Log In
Sign Up
Forgot Password?
or connect with