Skip to content

Instantly share code, notes, and snippets.

@maehrm
Created March 24, 2026 08:54
Show Gist options
  • Select an option

  • Save maehrm/34e874f4a9ba24ea2907d0afc0883a90 to your computer and use it in GitHub Desktop.

Select an option

Save maehrm/34e874f4a9ba24ea2907d0afc0883a90 to your computer and use it in GitHub Desktop.
import bisect
N = int(input())
WH = [list(map(int, input().split())) for _ in range(N)]
WH.sort(key=lambda x: (x[0], -x[1]))
lis = []
H = [h for _, h in WH]
for h in H:
idx = bisect.bisect_left(lis, h)
if idx == len(lis):
lis.append(h)
else:
lis[idx] = h
print(len(lis))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment