Night Market

Time limit1sMemory limit128 MB

Summary
Choose an increasing-index subset of stalls, each with a non-overlapping integer start time before T, so that no play interval strictly contains time S, maximizing total fun.
Level

Medium7 of 10

Topics
Dynamic programming, Greedy, Sorting, Implementation
Solved
No attempts yet

Problem

Taro is going to a summer festival.

Along the road to the festival there are NN night-market stalls, numbered 11 through NN in order. For each stall, the fun you gain by playing there and the time it takes to play are both integers. Playing at stall ii gives AiA_i fun and takes BiB_i time.

As the highlight of the festival there is a fireworks show, and the largest firework goes up at time SS. Taro really wants to watch this largest firework.

To enjoy both the stalls and the firework, Taro plans his schedule from the moment he arrives, time 00, until the festival ends at time TT.

Taro chooses kk stalls (1≤k≤N)(1 \le k \le N) and picks an integer visiting time for each. He cannot choose the same stall twice. Let the chosen stall numbers in increasing order be y1,y2,…,yky_1, y_2, \dots, y_k, and let xyix_{y_i} be the time he visits stall yiy_i; then Taro plays at stall yiy_i from time xyix_{y_i} to time xyi+Byix_{y_i} + B_{y_i}.

Taro plays at the stalls in increasing order of their numbers and cannot play at two stalls at the same time. The time to move between stalls is negligible.

Once time passes TT the festival ends, so he cannot play at any stall after that. Also, while he is playing at a stall he cannot watch the firework. However, if time SS is exactly the moment he starts or finishes playing at some stall, then Taro can still watch that firework.

That is, the plan must satisfy all of the following conditions.

  • y1<y2<⋯<yky_1 < y_2 < \dots < y_k
  • xy1,xy2,…,xykx_{y_1}, x_{y_2}, \dots, x_{y_k} are integers.
  • 0≤xy1<xy1+By1≤xy2<xy2+By2≤⋯≤xyk<xyk+Byk≤T0 \le x_{y_1} < x_{y_1} + B_{y_1} \le x_{y_2} < x_{y_2} + B_{y_2} \le \dots \le x_{y_k} < x_{y_k} + B_{y_k} \le T
  • There is no ii such that xyi<S<xyi+Byix_{y_i} < S < x_{y_i} + B_{y_i}.

Let MM be the sum of the fun values Ay1,Ay2,…,AykA_{y_1}, A_{y_2}, \dots, A_{y_k} of the chosen stalls. Taro wants to make MM as large as possible.

Given the information of the NN stalls and the times SS and TT, write a program that finds the maximum possible value of MM.

Input

The following is given on standard input.

The first line contains three integers NN, TT, SS separated by spaces: the number of stalls is NN, the festival ends at time TT, and the largest firework goes up at time SS.

Each of the next NN lines describes one stall. Line i+1i + 1 (1≤i≤N)(1 \le i \le N) contains two integers AiA_i and BiB_i separated by a space: playing at stall ii gives AiA_i fun and takes BiB_i time.

It is guaranteed that at least one valid plan exists for every input.

Output

Print the maximum value of MM as a single integer on one line.

Constraints

  • 1≤N≤30001 \le N \le 3000 — the number of stalls
  • 1≤T≤30001 \le T \le 3000 — the time the festival ends
  • 0≤S≤T0 \le S \le T — the time the largest firework goes up
  • 0≤Ai≤1000000 \le A_i \le 100000 — the fun gained by playing at stall ii
  • 1≤Bi≤30001 \le B_i \le 3000 — the time it takes to play at stall ii

Explanation

In the first example, the following plan maximizes MM.

  • Visit stall 11 at time 00 and play from time 00 to time 99.
  • Visit stall 22 at time 99 and play from time 99 to time 1313.
  • Visit stall 44 at time 1414 and play from time 1414 to time 1717.

The firework goes up at time S=14S = 14, which is exactly when Taro starts playing at stall 44, so he can still watch it. Here M=8+2+6=16M = 8 + 2 + 6 = 16.

Examples5

  1. Example 1

    Input
    5 20 14
    8 9
    2 4
    7 13
    6 3
    5 8
    
    Expected output
    16
    
  2. Example 2

    Input
    1 5 2
    7 3
    
    Expected output
    7
    
  3. Example 3

    Input
    3 10 0
    5 4
    6 3
    4 2
    
    Expected output
    15
    
  4. Example 4

    Input
    2 10 4
    5 4
    6 6
    
    Expected output
    11
    
  5. Example 5

    Input
    5 10 5
    3 2
    3 2
    3 2
    3 2
    3 2
    
    Expected output
    12