Hiring process8 levels
  1. 1 IQ Test
  2. 2 Additional Online Test (If Required)
  3. 3 Office Interview with Hiring Manager
  4. 4 Unpaid Test Task (Motivation Check)
  5. 5 Paid Test Task and Follow-Up Interview
  6. 6 Iterative Paid Test Tasks
  7. 7 Office Verification
  8. 8 Final Interview with the Founder

Problems > Minimize the Worst Delay

Minimize the Worst Delay

Difficulty: 1500 5000 ms 128 MB

greedy sorting

N jobs run on one machine (no overlap); job i takes di time and is due at ti. If a job finishes at time f its lateness is max(0, f − ti). Order the jobs to minimize the MAXIMUM lateness and print that value.

Input: the first line has N; each of the next N lines has duration and deadline.

Output: the minimum possible maximum lateness.

Constraints:

  • 1 ≤ N ≤ 105
  • 1 ≤ di ≤ 1000
  • 1 ≤ ti ≤ 106

Sample Tests

Input 1
2
3 5
2 4
Output 1
0
Input 2
1
5 3
Output 2
2

Read the Editorial Statistics

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.
Ctrl+Enter submit · Ctrl+Space autocomplete · F11 fullscreen