Problem: There is a function f(x), which is initially a constant function f(x) = 0.  We will ask you to process Q queries in order. There are two kinds of queries, update queries and evaluation queries, as follows:    * An update query `1 a b`: Given two integers a and b, let g(x) = f(x) + |x - a| + b and replace f(x) with g(x).   * An evaluation query `2`: Print x that minimizes f(x), and the minimum value of f(x). If there are multiple such values of x, choose the minimum such value.  We can show that the values to be output in an evaluation query are always integers, so we ask you to print those values as integers without decimal points.

Submission attempts (in order):
#!/usr/bin/env python3
import heapq


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    Q = int(input())
    sum_b = 0
    sum_al = 0
    sum_ar = 0
    hl = []
    hr = []
    for _ in range(Q):
        buf = input()
        if buf[0] == '1':
            _, a, b = map(int, buf.split())
            sum_b += b
            if len(hl) == 0:
                heapq.heappush(hl, -a)
                sum_al += a
                continue
            if len(hr) == 0:
                heapq.heappush(hr, a)
                sum_ar += a
                if -hl[0] > hr[0]:
                    hl[0], hr[0] = -hr[0], -hl[0]
                    sum_al, sum_ar = sum_ar, sum_al
                continue

            if a < -hl[0]:
                heapq.heappush(hl, -a)
                sum_al += a
            elif a > hr[0]:
                heapq.heappush(hr, a)
                sum_ar += a
            else:
                #if len(hl) <= len(hr):
                heapq.heappush(hl, -a)
                sum_al += a
                #else:
                #    heapq.heappush(hr, a)

            while len(hr) > len(hl):
                tmp = heapq.heappop(hr)
                sum_ar -= tmp
                heapq.heappush(hl, -tmp)
                sum_al += tmp
            while len(hl) > len(hl)+1:
                tmp = heapq.heappop(hl)
                sum_al -= tmp
                heapq.heappush(hr, -tmp)
                sum_ar += tmp

        else:
            tmp_al = -hl[0]*len(hl)-sum_al if len(hl) != 0 else 0
            tmp_ar = sum_ar-(-hl[0])*len(hr) if len(hl) != 0 else 0
            print(hl, sum_al, hr, sum_ar)
            print(-hl[0], tmp_al+tmp_ar+sum_b)

if __name__ == '__main__':
    main()


#!/usr/bin/env python3
import heapq


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    Q = int(input())
    sum_b = 0
    sum_al = 0
    sum_ar = 0
    hl = []
    hr = []
    for _ in range(Q):
        buf = input()
        if buf[0] == '1':
            _, a, b = map(int, buf.split())
            sum_b += b
            if len(hl) == 0:
                heapq.heappush(hl, -a)
                sum_al += a
                continue
            if len(hr) == 0:
                heapq.heappush(hr, a)
                sum_ar += a
                if -hl[0] > hr[0]:
                    hl[0], hr[0] = -hr[0], -hl[0]
                    sum_al, sum_ar = sum_ar, sum_al
                continue

            if a < -hl[0]:
                heapq.heappush(hl, -a)
                sum_al += a
            elif a > hr[0]:
                heapq.heappush(hr, a)
                sum_ar += a
            else:
                #if len(hl) <= len(hr):
                heapq.heappush(hl, -a)
                sum_al += a
                #else:
                #    heapq.heappush(hr, a)

            while len(hr) > len(hl):
                tmp = heapq.heappop(hr)
                sum_ar -= tmp
                heapq.heappush(hl, -tmp)
                sum_al += tmp
            while len(hl) > len(hr)+1:
                tmp = heapq.heappop(hl)
                sum_al -= -tmp
                heapq.heappush(hr, -tmp)
                sum_ar += -tmp

        else:
            tmp_al = -hl[0]*len(hl)-sum_al if len(hl) != 0 else 0
            tmp_ar = sum_ar-(-hl[0])*len(hr) if len(hl) != 0 else 0
            
            print(-hl[0], tmp_al+tmp_ar+sum_b)

if __name__ == '__main__':
    main()


Verdicts: Runtime Error

Accepted