CSES - Shared codeLink to this code:
https://cses.fi/paste/25ce406e0f776551711046/
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
# python optimise:
arr = sorted(map(lambda x: (x[0] << 32) + x[1], tasks))
ans = 0
curr_time = 0
for x in arr:
duration, deadline = x >> 32, x % (1 << 32)
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()