Skip to content

Instantly share code, notes, and snippets.

@terror
Created June 28, 2020 03:29
Show Gist options
  • Save terror/e9c92d59329d1b9d4cac9fc8186a13fb to your computer and use it in GitHub Desktop.
Save terror/e9c92d59329d1b9d4cac9fc8186a13fb to your computer and use it in GitHub Desktop.
Solution to bank queue Kattis problem for article
from heapq import heappush, heappop
n, t = list(map(int, input().split()))
people = {}
for i in range(n):
a, b = list(map(int, input().split()))
if b in people:
people[b].append(a)
else:
people[b] = [a]
q = []
tot = 0
for i in range(t-1, -1, -1):
if i in people:
for j in people[i]:
heappush(q, -j)
if q:
tot += heappop(q)
print(-tot)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment