AKVHYD01 - Joey is Hungry 200 pts
Joey just got free from a shooting and he wants to have lunch. Director of the movie gave him only "K" units of time for the lunch. There are "N" restaurants in the city. For the ith restaurant, there are two values that Joey knows, "Fi" and "Ti". Ti is the amount of time it would take if Joey eats lunch in the ith restaurant. If Ti is less than or equal to K, Joey will have Fi amount of fun in that restaurant. If Ti is greater than K, then Joey's fun will be calculated asĀ Fi - (Ti - K).
Joey has the list of all restaurants and Fi and Ti values for all of them. Please tell him the maximum fun that he can have. He will have his lunch in only one restaurant. The maximum can be negative also.
Input
First line will contain two integers N and K. Each of the next N lines will contain two integers Fi and Ti.
Output
Print a single integer that tells the maximum fun that Joey can have.
Constraints
1 <= N <= 10^4
1 <= K <= 10^9
1 <= Fi, Ti <= 10^9
Example
Input: 2 5 3 3 4 5 Output: 4
Input: 4 6 5 8 3 6 2 3 2 2 Output: 3
Input: 1 5 1 7 Output: -1
Added by: | Ankit Kumar Vats |
Date: | 2013-08-22 |
Time limit: | 1s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: ASM64 |