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):
# -*- coding: utf-8 -*-
"""
Created on Sat May 25 21:57:15 2019

@author: Yamazaki Kenichi
"""
import bisect

Q = int(input())
Q2 = [input() for i in range(Q)]

ans = []
A = []
B = 0
C = 0
counta = 0
d, prea, b = map(int,Q2[0].split()) 
for q in Q2:
    if q[0] == '1':
#        input
        d, a, b = map(int,q.split()) 
        bisect.insort_left(A,a)
#        if A[(len(A)-1)//2] > a:
#            C = abs(prea - a)
#        else:
#            C = abs(A[(len(A)-1)//2] - a)
        C = abs(A[(len(A)-1)//2] - a) if counta % 2 == 1 else abs(prea - a)
        B += (b + C)
#        C = abs(prea - a)
        prea = A[(len(A)-1)//2]
        counta += 1
    else:
#        output
        tmp = A[(len(A)-1)//2]
        ans.append([tmp,B])
for c in ans:
    print(' '.join(map(str,c)))

# -*- coding: utf-8 -*-
"""
Created on Sat May 25 22:55:33 2019

@author: Yamazaki Kenichi
"""
import heapq

Q = int(input())
Q2 = [input() for i in range(Q)]

ans = []
Al,Ar = [-(-(10**9+1))],[10**9+1]
B = 0
flg = False
for q in Q2:
    if q[0] == '1':
#        input
        d, a, b = map(int,q.split())
        if not flg:
            heapq.heappush(Al,-a)
            flg = True
            continue

        if len(Al) == len(Ar):
            if a < (-Al[0]):
                heapq.heappush(Al,-a)
                C = abs(a - (-Al[0]))
            else:
                heapq.heappush(Al,-(heapq.heappop(Ar)))
                heapq.heappush(Ar,a)
                C = abs(a - (-Al[0]))
        else:
            if a < (-Al[0]):
                heapq.heappush(Ar,-(heapq.heappop(Al)))
                heapq.heappush(Al,-a)
                C = abs(a - (Ar[0]))
            else:
                heapq.heappush(Ar,a)
                C = abs(a - (-Al[0]))
        B += (b + C)
#        print(Al,Ar,a)
    else:
#        output
        ans.append([(-Al[0]),B])
        
for c in ans:
    print(' '.join(map(str,c)))

# -*- coding: utf-8 -*-
"""
Created on Tue May 28 22:22:21 2019

@author: Yamazaki Kenichi
"""
import heapq

Q = int(input())
Q2 = [input() for i in range(Q)]

ans = []
Al,Ar = [-(-(10**9+1))],[10**9+1]
d, a, b = map(int,Q2[0].split())
heapq.heappush(Al,-a)
B = b

for i in range(1,Q):
    if Q2[i][0] == '1':
#        intput
        d, a, b = map(int,Q2[i].split())
        if len(Al) == len(Ar):
            if a < Ar[0]:
                heapq.heappush(Al,-a)
            else:
                heapq.heappush(Ar,a)
                heapq.heappush(Al,-(heapq.heappop(Ar)))
            C = abs(a - (-Al[0]))
        else:
            C = abs(a - (-Al[0]))
            if a < Ar[0]:
                heapq.heappush(Al,-a)
                heapq.heappush(Ar,-(heapq.heappop(Al)))
            else:
                heapq.heappush(Ar,a)
        B += (b + C)
#        print(Al,Ar,a,B,b)
    else:
#        output
        ans.append([(-Al[0]),B])

for c in ans:
    print(' '.join(map(str,c)))



Verdicts: Wrong Answer

Wrong Answer

Accepted