https://cses.fi/paste/972de727f25b8f1171102a/
import sys input = sys.stdin.readline def solve(n, tasks): # we can see that deadline doesnt matter cuz we always have to do the task tasks.sort() ans = 0 curr_time = 0 for duration, deadline in tasks: curr_time += duration ans += deadline - curr_time print(ans) def main(): n = int(input()) tasks = [list(map(int, input().split())) for _ in range(n)] solve(n, tasks) main()