Created
June 28, 2020 03:29
-
-
Save terror/e9c92d59329d1b9d4cac9fc8186a13fb to your computer and use it in GitHub Desktop.
Solution to bank queue Kattis problem for article
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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