Skip to main content
Back to problems
Codeforces
Easy
Arrays
Math
Greedy
Lunch Rush

Choose the restaurant that maximizes your profit after accounting for the hunger of the customers and the restaurant's delay penalty.

Acceptance 0%
Problem Statement

Lunch Rush

N friends are going to have lunch. For the ii-th restaurant, you know two values:

  • fif_i: the amount of money you would gain if you eat there.
  • sis_i: the number of friends who will become unhappy because of the waiting time.

Your actual profit from choosing restaurant ii is:

profiti=fisiprofit_i = f_i - s_i

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 nn — the number of restaurants.
  • The next nn lines each contain two integers fif_i and sis_i.

Output Format

Print one integer — the maximum value of fisif_i - s_i over all restaurants.

Constraints

  • 1n1001 \le n \le 100
  • 1fi,si1001 \le f_i, s_i \le 100
Examples
Sample cases returned by the problem API.

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.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.