Submission #1366714

#TimeUsernameProblemLanguageResultExecution timeMemory
1366714makonGrilled Bottle (KAISTRUN26SPRING_D)Pypy 3
100 / 100
2157 ms357764 KiB
import sys, heapq
input = sys.stdin.readline

def main():
    n, m = map(int, input().split())

    a = [tuple(map(int, input().split())) for _ in range(n)]
    b = list(map(int, input().split()))

    a.sort(reverse=True)

    def f(k, flag=False):
        c = b[:k]
        c.sort(reverse=True)

        h = []
        j = 0
        s = 0

        for x in c:
            while j < n and a[j][0] >= x:
                heapq.heappush(h, -a[j][1])
                j += 1

            if not h:
                return (False, 0) if flag else False

            s -= heapq.heappop(h)

        return (True, s) if flag else True

    l, r = 0, min(n, m)

    while l < r:
        mid = (l + r + 1) // 2
        if f(mid):
            l = mid
        else:
            r = mid - 1

    _, ans = f(l, True)
    print(l, ans)

if __name__ == "__main__": main()

Compilation message (stdout)

Compiling 'Main.py'...

=======
  adding: __main__.pyc (deflated 35%)

=======
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...