Skip to content

Instantly share code, notes, and snippets.

@maehrm
Created March 24, 2026 12:36
Show Gist options
  • Select an option

  • Save maehrm/2739a92d7a4222deeb1b87f7256d0aac to your computer and use it in GitHub Desktop.

Select an option

Save maehrm/2739a92d7a4222deeb1b87f7256d0aac to your computer and use it in GitHub Desktop.
from collections import defaultdict
N = int(input())
events = defaultdict(int)
for _ in range(N):
A, B = map(int, input().split())
events[A] += 1
events[A + B] -= 1
days = sorted(events.keys())
num = defaultdict(int)
curr = 0 # 現在の人数
for i in range(len(days) - 1):
now = days[i]
nxt = days[i + 1]
curr += events[now]
period = nxt - now
if curr > 0:
num[curr] += period # 現在の人数が続いた日数
ans = [0] * (N + 1)
for k, v in num.items():
ans[k] = v
print(*ans[1:])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment