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):
def absolute_minima(Q: int, queries: list)->list:
    L, R = [], []
    sL, sR = 0, 0
    M = None
    B = 0
    N = 0

    res = []

    for query in queries:
        if query[0] == 1:
            _, a, b = query
            N += 1
            B += b

            if M == None:
                M = a
            else:
                if M < a:
                    R.append(a)
                    sR += a
                else:
                    L.append(a)
                    sL += a

                while len(R)-len(L) > 1:
                    L.append(M)
                    sL += M

                    M = R[0]

                    R.remove(M)
                    sR -= M

                while len(L) > len(R):
                    R.append(M)
                    sR += M

                    M = L[0]

                    L.remove(M)
                    sL -= M

        else:
            s = - sL + sR + B
            if N & 1 == 0:
                s -= M
            res.append((M, s))

    return res


if __name__ == "__main__":
    Q = int(input())
    queries = [tuple(int(s) for s in input().split()) for _ in range(Q)]

    for ans in absolute_minima(Q, queries):
        print(ans)


def absolute_minima():
    Q = int(input())

    L, R = [], []
    sL, sR = 0, 0
    M = None
    B = 0
    N = 0

    for _ in range(Q):
        query = map(int, input().split())

        if query[0] == 1:
            _, a, b = query
            N += 1
            B += b

            if M == None:
                M = a
            else:
                if M < a:
                    R.append(a)
                    sR += a
                else:
                    L.append(a)
                    sL += a

                while len(R)-len(L) > 1:
                    L.append(M)
                    sL += M

                    M = R[0]

                    R.remove(M)
                    sR -= M

                while len(L) > len(R):
                    R.append(M)
                    sR += M

                    M = L[0]

                    L.remove(M)
                    sL -= M

        else:
            s = - sL + sR + B
            if N & 1 == 0:
                s -= M
            print(M, s)


if __name__ == "__main__":
    absolute_minima()


import heapq


class PriorityQueue:
    def __init__(self):
        self.__heap = []
        self.__count = 0

    def empty(self) -> bool:
        return self.__count == 0

    def dequeue(self):
        if self.empty():
            raise Exception('empty')
        self.__count -= 1
        return heapq.heappop(self.__heap)

    def enqueue(self, v):
        self.__count += 1
        heapq.heappush(self.__heap, v)

    def __len__(self):
        return self.__count


def absolute_minima():
    Q = int(input())

    L, R = PriorityQueue(), PriorityQueue()
    sL, sR = 0, 0
    M = None
    B = 0
    N = 0

    for _ in range(Q):
        query = [int(s) for s in input().split()]

        if query[0] == 1:
            _, a, b = query
            B += b
            N += 1

            if M is None:
                M = a
            elif M < a:
                R.enqueue(a)
                sR += a
            else:
                L.enqueue(-a)
                sL += a

            while len(R)-len(L) > 1:
                L.enqueue(-M)
                sL += M

                M = R.dequeue()
                sR -= M

            while len(L) > len(R):
                R.enqueue(M)
                sR += M

                M = -L.dequeue()
                sL -= M

        else:
            s = - sL + sR + B
            if N % 2 == 0:
                s -= M
            print(M, s)


if __name__ == "__main__":
    absolute_minima()


Verdicts: Wrong Answer

Runtime Error

Accepted