Night Market
Time limit1sMemory limit128 MB
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 night-market stalls, numbered through 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 gives fun and takes time.
As the highlight of the festival there is a fireworks show, and the largest firework goes up at time . 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 , until the festival ends at time .
Taro chooses stalls and picks an integer visiting time for each. He cannot choose the same stall twice. Let the chosen stall numbers in increasing order be , and let be the time he visits stall ; then Taro plays at stall from time to time .
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 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 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.
- are integers.
- There is no such that .
Let be the sum of the fun values of the chosen stalls. Taro wants to make as large as possible.
Given the information of the stalls and the times and , write a program that finds the maximum possible value of .
Input
The following is given on standard input.
The first line contains three integers , , separated by spaces: the number of stalls is , the festival ends at time , and the largest firework goes up at time .
Each of the next lines describes one stall. Line contains two integers and separated by a space: playing at stall gives fun and takes time.
It is guaranteed that at least one valid plan exists for every input.
Output
Print the maximum value of as a single integer on one line.
Constraints
- — the number of stalls
- — the time the festival ends
- — the time the largest firework goes up
- — the fun gained by playing at stall
- — the time it takes to play at stall
Explanation
In the first example, the following plan maximizes .
- Visit stall at time and play from time to time .
- Visit stall at time and play from time to time .
- Visit stall at time and play from time to time .
The firework goes up at time , which is exactly when Taro starts playing at stall , so he can still watch it. Here .