Choose the restaurant that maximizes your profit after accounting for the hunger of the customers and the restaurant's delay penalty.
Lunch Rush
N friends are going to have lunch. For the -th restaurant, you know two values:
- : the amount of money you would gain if you eat there.
- : the number of friends who will become unhappy because of the waiting time.
Your actual profit from choosing restaurant is:
Your task is to find the maximum possible profit among all restaurants.
Idea
This is a direct evaluation problem: compute the profit for each restaurant and keep the best one.
Input Format
- The first line contains an integer — the number of restaurants.
- The next lines each contain two integers and .
Output Format
Print one integer — the maximum value of over all restaurants.
Constraints
Example 1
Input
3 8 1 4 4 5 2
Output
7
Explanation
The profits are 8-1=7, 4-4=0, and 5-2=3. The maximum is 7.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.