Minimum money

0

0 votes
Easy
Problem

You are given information about n items that you selected in a store.

For each item, you are given P and T.

P denotes the cost of item and T denotes the time needed to check the item by Security.

While security checks that item, you can remove some items from the given selected items.

You take 1 second to steal any of the selected item.

Note: You can only remove items till security is busy in checking.

You want to know the minimum money you have to give to purchase those 'n' items.

Note: You can optimally determine the order of items which security has to check.


Input format: 

The first input line contains number n. 

In each of the following n lines each item is described by a pair of numbers T, P. 

If T = 0, no item can be stolen.


Output format:

Output required answer.


Constraints:

1 <= n <= 2000

0 <= T <= 2000

1 <= P <= 10^9

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

optimal way is to purchase 3rd and 4th items.

On purchasing 3rd item, you can steal 1st item.

On purchasing 4th item, youcan steal 2nd item.

Thus all items are purchased.

So minimum money to pay is 8.

Editor Image

?