Problem:


ワカサギ釣り大会 2

桧原湖でワカサギ釣り大会が行われました。今回はキャッチ＆リリースが推奨されているようです。

参加者番号と釣った匹数またはリリースした匹数を１つのイベントとして順番に読み込み、各イベントの直後に最も多くのワカサギを手元に獲得している参加者番号と匹数を出力するプログラムを作成してください。最も多く獲得している参加者が複数いる場合（あるいは全ての参加者が 0 匹の場合）は、その中で参加者番号が最も小さい一人を出力してください。

入力

入力は以下の形式で与えられる。

n q
a1 v1
a2 v2
: 
aq vq

n (1 ≤ n ≤ 1000000) は参加者の数、q (1 ≤ q ≤ 100000)はイベントの数を表す。ai (1 ≤ ai ≤ n)   vi ( -100 ≤ vi ≤ 100) は、i 番目のイベントで参加者 ai が vi 匹獲得あるいはリリースしたことを示す。vi は正の値が獲得、負の値がリリースを示し、0 が与えられることはない。

出力

各イベントごとに、最も多くのワカサギを手元に獲得している参加者の参加者番号と匹数を１つの空白区切りで１行に出力する。

入力例1

3 5
1 4 
2 5 
1 3
3 6
2 7

出力例1

1 4
2 5
1 7
1 7
2 12

入力例2

3 5
1 4 
2 5 
2 -3
3 4
1 -1

出力例2

1 4
2 5
1 4
1 4
3 4



Sample input:
3 5
1 4
2 5
1 3
3 6
2 7


Sample output:
1 4
2 5
1 7
1 7
2 12

Submission status: Wrong Answer

Solution code:
def f(): return map(int,raw_input().split())
n,q=f()
A=[[0,i] for i in range(n+1)]
for _ in range(q):
  a,b=f()
  A[a][0]+=b
  m0,m1=max(A)
  print m1,m0

Submission status: Wrong Answer

Solution code:
n, q = map(int, raw_input().split())
dic = {}
for i in xrange(q):
    a, c = map(int, raw_input().split())
    if a in dic:
        dic[a] = dic[a] + c
    else:
        dic[a] = c
        
    f, m = sorted(dic.items(), key=lambda x: x[1], reverse=True)[0]
    print f, m

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
n, q = map(int, raw_input().split())
dic = {}
for i in xrange(q):
    a, c = map(int, raw_input().split())
    if a in dic:
        dic[a] = dic[a] + c
    else:
        dic[a] = c
    x = None
    y = None
    for k, v in sorted(dic.items(), key=itemgetter(1,0), reverse=True):
        if x == None:
            x = k
            y = v
        else:
            if y == v:
                x = k
                y = v
            else:
                print x, y
                break

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
n, q = map(int, raw_input().split())
dic = {}
for i in xrange(q):
    a, c = map(int, raw_input().split())
    if a in dic:
        dic[a] = dic[a] + c
    else:
        dic[a] = c
    c = sorted(dic.items(), reverse=True)[0][1]
    for index, t in enumerate(sorted(dic.items(), reverse=True)):
        if t[1] != c:
            x, y = sorted(dic.items(), key=itemgetter(1), reverse=True)[index-1]
            print x, y
            break
    else:
        print t[0], t[1]

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
n, q = map(int, raw_input().split())
dic = {}
for i in xrange(q):
    a, c = map(int, raw_input().split())
    if a in dic:
        dic[a] = dic[a] + c
    else:
        dic[a] = c
        
    check = None
    ans = None
    for index, t in enumerate(sorted(dic.items(), key=itemgetter(1,0), reverse=True)):
        if check == None:
            check = t
        elif check[1] == t[1]:
            ans = t
        else:
            if ans:
                print ans[0], ans[1]
            else:
                print check[0], check[1]
            break
    else:
        print check[0], check[1]

Submission status: Wrong Answer

Solution code:
r, q = list(map(int, input().split()))
cnt = [0 for _ in range(r + 1)]
mx = [0, -1]
for _ in range(q):
    a, v = list(map(int, input().split()))
    cnt[a] += v
    if mx[0] == a:
        mx[1] += v

    if cnt[a] > mx[1]:
        print("%d %d" % (a, cnt[a]))
        mx[0], mx[1] = a, cnt[a]
    else:
        print("%d %d" % (mx[0], mx[1]))

Submission status: Wrong Answer

Solution code:
n, q = list(map(int, input().split()))
cnt = [0 for _ in range(n + 1)]
cnt[0] = -1
mx = [0, -1]


def spam():
#    max_v = max(cnt)
#    idx = min([i for i, value in enumerate(cnt) if value == max_v])
#    return idx, max_v
    return 1,1

for _ in range(q):
    a, v = list(map(int, input().split()))
    cnt[a] += v
    if mx[0] == a and v > 0:
        mx[1] += v
    # elif mx[0] == a and v < 0:

        # mx = spam()

    if cnt[a] > mx[1]:
        print("%d %d" % (a, cnt[a]))
        mx[0], mx[1] = a, cnt[a]
    else:
        print("%d %d" % (mx[0], mx[1]))

Submission status: Wrong Answer

Solution code:
n, q = list(map(int, input().split()))
cnt = [0 for _ in range(n + 1)]
cnt[0] = -1
mx = [0, -1]


def spam():
    max_v = max(cnt)
    idx = min([i for i, value in enumerate(cnt) if value == max_v])
    return idx, max_v

for _ in range(q):
    a, v = list(map(int, input().split()))
    cnt[a] += v
    if mx[0] == a and v > 0:
        mx[1] += v
    elif mx[0] == a and v < 0:

        mx[0], mx[1] = spam()

    if cnt[a] > mx[1]:
        print("%d %d" % (a, cnt[a]))
        mx[0], mx[1] = a, cnt[a]
    else:
        print("%d %d" % (mx[0], mx[1]))

Submission status: Wrong Answer

Solution code:
n, q = list(map(int, input().split()))
cnt = [0 for _ in range(n + 1)]
cnt[0] = -1
mx = [0, -1]


def spam():
    max_v = max(cnt)
    idx = min([i for i, value in enumerate(cnt) if value == max_v])
    return idx, max_v

for _ in range(q):
    a, v = list(map(int, input().split()))
    cnt[a] += v
    if mx[0] == a and v > 0:
        mx[1] += v
    elif cnt[a] > mx[1]:
        mx[0], mx[1] = spam()

    if cnt[a] > mx[1]:
        print("%d %d" % (a, cnt[a]))
        mx[0], mx[1] = a, cnt[a]
    else:
        print("%d %d" % (mx[0], mx[1]))

Submission status: Wrong Answer

Solution code:
n, q = list(map(int, input().split()))
cnt = [0 for _ in range(n + 1)]
cnt[0] = -1
mx = [0, -1]


def spam():
    max_v = max(cnt)
    idx = min([i for i, value in enumerate(cnt) if value == max_v])
    return idx, max_v

for _ in range(q):
    a, v = list(map(int, input().split()))
    cnt[a] += v
    if mx[0] == a and v > 0:
        mx[1] += v
    elif mx[0] == a or cnt[a] > mx[1]:
        mx[0], mx[1] = spam()

    if cnt[a] > mx[1]:
        print("%d %d" % (a, cnt[a]))
        mx[0], mx[1] = a, cnt[a]
    else:
        print("%d %d" % (mx[0], mx[1]))

Submission status: Wrong Answer

Solution code:
n, q = list(map(int, input().split()))
cnt = [0 for _ in range(n + 1)]
cnt[0] = -1
mx = [0, -1]


def spam():
    max_v = max(cnt)
    idx = min([i for i, value in enumerate(cnt) if value == max_v])
    return idx, max_v

for _ in range(q):
    a, v = list(map(int, input().split()))
    cnt[a] += v
    if mx[0] == a and v > 0:
        mx[1] += v

    elif mx[0] == a:
        mx[0], mx[1] = spam()
    else:
        mx[0], mx[1] = a, cnt[a]

    print("%d %d" % (mx[0], mx[1]))

Submission status: Wrong Answer

Solution code:
n, q = list(map(int, input().split()))
cnt = [0 for _ in range(n + 1)]
cnt[0] = -9999999999
mx = [0, cnt[0]]


def spam():
    max_v = max(cnt)
    idx = min([i for i, value in enumerate(cnt) if value == max_v])
    return idx, max_v

for _ in range(q):
    a, v = list(map(int, input().split()))
    cnt[a] += v
    if mx[0] == a and v > 0:
        mx[1] += v

    elif mx[0] == a:
        mx[0], mx[1] = spam()
    else:
        mx[0], mx[1] = a, cnt[a]

    print("%d %d" % (mx[0], mx[1]))

Submission status: Wrong Answer

Solution code:
l={}
tmp=[-1,-1]
n,q=map(int,raw_input().split())
for i in range(q):
    a,v=map(int,raw_input().split())
    if l.has_key(a):
        l[a]+=v
    else:
        l[a]=v
    if tmp[0]==-1:
        tmp=[a,v]
    elif l[a]>tmp[1]:
        tmp=[a,l[a]]
    elif l[a]==tmp[1] and a<tmp[0]:
        tmp[0]=a
    if a==tmp[0] and v<0:
        tmp=[-1,-1]
        for i in l:
            if tmp[0]==-1:
                tmp=[i,l[i]]
            elif l[i]>tmp[1]:
                tmp=[i,l[i]]
            elif l[i]==tmp[1] and i<tmp:
                tmp[0]=i
    print tmp[0],tmp[1]

Submission status: Wrong Answer

Solution code:
n,q=map(int,raw_input().split())
ans=[0]*n
key=value=0
for i in range(q):
    a,v=map(int,raw_input().split())
    a-=1
    ans[a]=ans[a]+v
    if a==key and v<0:
        value=max(ans)
        key=ans.index(value)
    elif ans[a]>value:
        key=a
        value=ans[a]
    elif ans[a]==value and a<key:
        key=0
    print key+1,value

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
n, q = [int(el) for el in input().split(' ')]
data = {}
for _ in range(q):
    a, v = [int(el) for el in input().split(' ')]
    if a in data:
        data[a] += v
    else:
        data[a] = v
    print(*max(data.items(), key=itemgetter(1)))

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
from collections import OrderedDict
n, q = [int(el) for el in input().split(' ')]
data = OrderedDict({n:0 for i in range(n)})
for _ in range(q):
    a, v = [int(el) for el in input().split(' ')]
    if a in data:
        data[a] += v
    else:
        data[a] = v
    print(*max(data.items(), key=itemgetter(1)))

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
from collections import OrderedDict
n, q = [int(el) for el in input().split(' ')]
data = OrderedDict({i:0 for i in range(n,0,-1)})
print(data)
for _ in range(q):
    a, v = [int(el) for el in input().split(' ')]
    data[a] += v
    print(*max(data.items(), key=itemgetter(1)))

Submission status: Wrong Answer

Solution code:
n, q = [int(el) for el in input().split(' ')]
data = [0] * n
ex_result = 0
ex_index = 0
for _ in range(q):
    a, v = [int(el) for el in input().split(' ')]
    data[a-1] += v
    if ex_index != a:
        if ex_result > data[a-1]:
            result = ex_result
            index = ex_index
        else:
            result = data[a-1]
            index = a-1
    elif ex_index == a:
        if v > 0:
            result = data[a-1]
            index = ex_index
        else:
            result = max(data)
            index = data.index(result)+1
    print(index, result)
    ex_result = result
    ex_index = index

Submission status: Wrong Answer

Solution code:
n, q = [int(el) for el in input().split(' ')]
data = [0] * n
result, index = 0, 0
for _ in range(q):
    a, v = [int(el) for el in input().split(' ')]
    data[a-1] += v
    if index != a:
        if result < data[a-1]:
            result = data[a-1]
            index = a
    elif index == a:
        if v > 0:
            result = data[a-1]
        else:
            result = max(data)
            index = data.index(result)+1
    print(index, result)

Submission status: Wrong Answer

Solution code:
n, q = [int(el) for el in input().split(' ')]
data = [0] * n
result, index = 0, 1
for _ in range(q):
    a, v = [int(el) for el in input().split(' ')]
    data[a-1] += v
    if v > 0:
        if result < data[a-1]:
            result, index = data[a-1], a
        elif result == data[a-1]:
            index = min(index, a-1)
    else:
        if index == a:
            result = max(data)
            index = data.index(result) + 1
    print(index, result)

Submission status: Wrong Answer

Solution code:
n,q=map(int,input().split())

A=[[int(i),0] for i in range(n)]
for i in range(q):
	a,v=map(int,input().split())
	A[a-1][1]+=v
	Max=A[0][1]
	champ=A[0][0]
	for j in A:
		if j[1]>Max:
			champ=j[0]
	print(A[champ][0]+1,A[champ][1])

Submission status: Wrong Answer

Solution code:
def liquidation(A):
	A.sort()#??????????????????????????????
	for i in range(len(A)):
		for j in range(i+1,len(A)):
			if A[i][0]==A[j][0]:
				A[i][1]+=A[j][1]
				del A[j]
				break
	return A

def liquidation1(A):
	for i in A[:-1]:
		if A[-1][0]==i[0]:
			i[1]+=A[-1][1]
			del A[-1]
			break
	return A




def rank(A):
	Max=A[0][1]
	champ=A[0][0]
	for i in A:
		if Max<i[1]:
			champ=i[0]
			Max=i[1]
	print(champ,Max)


n,q=map(int,input().split())
A=[]
for i in range(q):
	a,v=map(int,input().split())
	A.append([a,v])#a??????????????????, v?????£??£???????????°
	A=liquidation1(A)
	rank(A)

Submission status: Wrong Answer

Solution code:
[n,q]=[int(x) for x in raw_input().split()]
qlist=[]
for i in range(q):
    qlist.append([int(x) for x in raw_input().split()])
qlist.sort(key= lambda x:x[0])
ans=qlist[0][0]
maxsc=0
person=qlist[0][0]
score=0
for i in range(q):
    p=qlist[i][0]
    if p!=person:
        if score>maxsc:
            maxsc=score
            ans=person
        person=p
        score=qlist[i][1]
    else:
        score+=qlist[i][1]
if score>maxsc:
    maxsc=score
    ans=person
print ans,maxsc

Submission status: Wrong Answer

Solution code:
[n,q]=[int(x) for x in raw_input().split()]
sclist=[0 for i in range(n+1)]
maxman=1
for i in range(q):
    [m,s]=[int(x) for x in raw_input().split()]
    sclist[m]+=s
    if sclist[maxman]<sclist[m]:
        maxman=m
    print maxman,sclist[maxman]

Submission status: Wrong Answer

Solution code:
[n,q]=[int(x) for x in raw_input().split()]
sclist=[0 for i in range(n+1)]
maxman=1
secmaxman=2
for i in range(q):
    [m,s]=[int(x) for x in raw_input().split()]
    sclist[m]+=s
    if m in [maxman,secmaxman]:
        temp1=sorted(sorted([[maxman,sclist[maxman]],[secmaxman,sclist[secmaxman]]],key=lambda y:y[0]),key=lambda x:x[1],reverse =1)
        [maxman,secmaxman]=[temp1[0][0],temp1[1][0]]
    else:
        temp1=sorted(sorted([[maxman,sclist[maxman]],[secmaxman,sclist[secmaxman]],[m,sclist[m]]],key=lambda y:y[0]),key=lambda x:x[1],reverse =1)
        [maxman,secmaxman]=[temp1[0][0],temp1[1][0]]
    print maxman,sclist[maxman]

Submission status: Wrong Answer

Solution code:
import bisect

[n,q]=[int(x) for x in raw_input().split()]
L=[[y*1000+x for x in range(1000)] for y in range(1000)]
M=[0 for x in range(1000000)]
medlist=[L[y][-1] for y in range(1000)]
Mmedlist=[0 for y in range(1000)]
for i in range(q):
    [a,v]=[int(x) for x in raw_input().split()]
    a-=1
    ind=bisect.bisect_left(L[a/1000],M[a]+a)
    k=L[a/1000].pop(ind)
    k+=v*10000000
    M[a]+=v*10000000
    bisect.insort_left(L[a/1000],k)
    
    ind=bisect.bisect_left(medlist,Mmedlist[a/1000])
    kk=max(medlist.pop(ind),k)
    Mmedlist[a/1000]=kk/10000000*10000000
    bisect.insort_left(medlist,kk)
    
    maxw=medlist[-1]/10000000
    print medlist[bisect.bisect_left(medlist,maxw*10000000)]%10000000+1,maxw

Submission status: Wrong Answer

Solution code:
import bisect

[n,q]=[int(x) for x in raw_input().split()]
L=[[y*1000+x for x in range(1000)] for y in range(1000)]
M=[0 for x in range(1000000)]
medlist=[L[y][-1] for y in range(1000)]
Mmedlist=[0 for y in range(1000)]
for i in range(q):
    [a,v]=[int(x) for x in raw_input().split()]
    a-=1
    ind=bisect.bisect_left(L[a/1000],M[a]+a)
    k=L[a/1000].pop(ind)
    k+=v*10000000
    M[a]+=v*10000000
    bisect.insort_left(L[a/1000],k)
    maxw=L[a/1000][-1]/10000000
    k=L[a/1000][bisect.bisect_left(L[a/1000],maxw*10000000)]
    
    ind=bisect.bisect_left(medlist,Mmedlist[a/1000])
    medlist.pop(ind)
    Mmedlist[a/1000]=k/10000000*10000000
    bisect.insort_left(medlist,k)
    
    maxw=medlist[-1]/10000000
    print medlist[bisect.bisect_left(medlist,maxw*10000000)]%10000000+1,maxw

Submission status: Wrong Answer

Solution code:
n,q = map(int,input().split())
Men = []
Res = []
for i in range(q):
    a,v = map(int,input().split())
    if a in Men:
        Res[Men.index(a)] += v
    else:
        Men.append(a)
        Res.append(v)
    print(Men[Res.index(max(Res))],Res[Res.index(max(Res))])

Submission status: Wrong Answer

Solution code:
import bisect
from math import modf

[n,q]=map(int,raw_input().split())
decp=1./(n+2)
A=[0 for i in range(n+1)]
B=[1-decp*(i+1) for i in range(1,n+1)]
B.sort()
for i in range(q):
    [a,v]=map(int,raw_input().split())
    pp=A[a]+ (1-decp*(a+1))
    A[a]+=v
    remind=bisect.bisect_left(B,pp)
    print B,pp+v,remind,pp
    B.pop(remind)
    bisect.insort(B,pp+v)
    decimal, integer = modf(B[-1])
    print int(round((1-decimal)*(n+2)-1,0)) , int(integer)

Submission status: Wrong Answer

Solution code:
import bisect
from math import modf

[n,q]=map(int,raw_input().split())
decp=1./(n+2)
A=[0 for i in range(n+1)]
B=[1-decp*(i+1) for i in range(1,n+1)]
B.sort()
for i in range(q):
    [a,v]=map(int,raw_input().split())
    pp=A[a]+ (1-decp*(a+1))
    A[a]+=v
    remind=min(bisect.bisect_left(B,pp),n-1)
    B.pop(remind)
    bisect.insort(B,pp+v)
    decimal, integer = modf(B[-1])
    print int(round((1-decimal)*(n+2)-1,0)) , int(integer)

Submission status: Wrong Answer

Solution code:
a={}
_,q=map(int,input().split())
for i in range(q):
    b,c=map(int,input().split())
    if b in a:a[b]+=c
    else:a[b]=c
    print(*max(a.items(),key=lambda x:x[1]))

Submission status: Wrong Answer

Solution code:
a={}
_,q=map(int,input().split())
for i in range(q):
    b,c=map(int,input().split())
    if b in a:a[b]+=c
    else:a[b]=c
    d=max(a.items(),key=lambda x:x[1])
    if d[1]==0:print(*min(a.items(),key=lambda x:x[0]))
    else:print(*d)

Submission status: Wrong Answer

Solution code:
a={}
_,q=map(int,input().split())
for i in range(q):
    b,c=map(int,input().split())
    e=[]
    if b in a:a[b]+=c
    else:a[b]=c
    d=max(a.items(),key=lambda x:x[1])
    for i,x in enumerate(a):
        if(x==d[1]):e+=[i,x]
    try:print(*min(e,key=lambda x:x[0]))
    except:print(*d)

Submission status: Wrong Answer

Solution code:
n,q = map(int,input().split())

a = [0]*(n+1)
first = 1
firstp = 0

for i in range(q):
    p,v = map(int,input().split())
    if v > 0:
        if a[p] == first:
            a[p] += v
            first = a[p]
        else:
            a[p] += v
            if a[p] > first:
                first = a[p]
                firstp = p 
    else:
        if a[p] != first:
            a[p] += v
        else:
            a[p] += v
            first = max(a)
            firstp = a.index(first)
    print(firstp,first)

Submission status: Wrong Answer

Solution code:
n,q = map(int,input().split())

a = [0]*(n+1)
first = 1
firstp = 0

for i in range(q):
    p,v = map(int,input().split())
    if v > 0:
        if a[p] == first:
            a[p] += v
            first = a[p]
        else:
            a[p] += v
            if a[p] > first:
                first = a[p]
                firstp = p
            elif a[p] == first:
                firstp = a.index(a[p]) 
    else:
        if a[p] != first:
            a[p] += v
        else:
            a[p] += v
            first = max(a)
            firstp = a.index(first)
    print(firstp,first)

Submission status: Wrong Answer

Solution code:
n,q = map(int,input().split())

a = [0]*(n+1)
first = -1
firstp = n+1

for i in range(q):
    p,v = map(int,input().split())
    if v > 0:
        if a[p] == first:
            a[p] += v
            first = a[p]
        else:
            a[p] += v
            if a[p] > first:
                first = a[p]
                firstp = p
            elif a[p] == first:
                firstp = a.index(a[p]) 
    else:
        if a[p] != first:
            a[p] += v
        else:
            a[p] += v
            first = max(a)
            firstp = a.index(first)
    print(firstp,first)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

import sys
import os

n, q = map(int, input().split())

scores = [0 for i in range(n)]
print(scores)
for i in range(q):
    a, v = map(int, input().split())

    # add
    a -= 1
    scores[a] += v

    max_value = max(scores)
    max_index = scores.index(max_value)

    print(max_index + 1, max_value)

Submission status: Wrong Answer

Solution code:
n, q = map(int, input().split())
n = [0]*(n+1)
maxv = 0
winner = []
for _ in range(q):
    a, v = map(int, input().split())
    n[a] += v
    if n[a] > maxv:
        maxv = n[a]
        winner.append(n.index(maxv))
    elif n[a] == maxv:
        i = len(winner)
        while winner[i-1] < a and i > 0:
            i -= 1
        winner.insert(i, a)
    if v < 0:
        winner.pop()
        maxv = n[winner[-1]]
    print(winner[-1], maxv)

Submission status: Wrong Answer

Solution code:
n, q = map(int, input().split())
n = [0]*(n+1)
maxv = winner = 0
for _ in range(q):
    a, v = map(int, input().split())
    n[a] += v
    if v < 0:
        maxv = max(n)
        winner = n.index(maxv)
    else:
        if n[a] > maxv:
            maxv = n[a]
            winner = a
    print(winner, maxv)

Submission status: Wrong Answer

Solution code:
n, q = [int(_) for _ in input().split()]
key, value = [], []
for _ in range(q) :
    a, v = [int(_2) for _2 in input().split()]
    if a not in key : 
        key.append(a)
        value.append(v)
    else : 
        value[key.index(a)] += v
    print(key[value.index(max(value))], max(value))

Submission status: Wrong Answer

Solution code:
from array import array
n, q = [int(_) for _ in input().split()]
book = array('b', [0] * (n+1))
for _ in range(q) :
    a, v = [int(_2) for _2 in input().split()]
    if a in book : book[a] += v
    else : book[a] = v
    print(book.index(max(book)), max(book))

Submission status: Wrong Answer

Solution code:
from array import array
n, q = [int(_) for _ in input().split()]
book = array('b', [0] * (n+2))
for _ in range(q) :
    a, v = [int(_2) for _2 in input().split()]
    if a in book : book[a] += v
    else : book[a] = v
    print(book.index(max(book)), max(book))
    print(book)

Submission status: Wrong Answer

Solution code:
n, q = [int(_) for _ in input().split()]
book = [0] * (n+1)
max_per, max_val = n, 0
for _ in range(q) :
    a, v = [int(_2) for _2 in input().split()]
    book[a] += v
    if max_val < book[a] : max_per, max_val = a, book[a]
    elif max_val == book[a] :
        if a < book[a] : max_per, max_val = a, book[a]
    print(max_per, max_val)

Submission status: Wrong Answer

Solution code:
a, q = map(int, input().split())
max_per, max_val = q, 0
book = [0] * (a+1)
for _ in [input()]*q :
    a, v = map(int, _.split())
    book[a] += v
    if v < 0 :
        max_val = max(book)
        max_per = book.index(max_val)
    elif max_val < book[a] : max_per, max_val = a, book[a]
    elif max_val == book[a] and a < max_per : max_per = a
    print(max_per, max_val)

Submission status: Wrong Answer

Solution code:
a, q = map(int, input().split())
max_per, max_val = q, 0
book = [0] * (a+1)
for _ in [0]*q :
    a, v = map(int, input().split())
    book[a] += v
    if v >= 0 :
        if   book[a] < max_val : pass
        elif max_val < book[a] : max_per, max_val = a, book[a]
        elif       a < max_per : max_per = a
    else :
        max_val = max(book)
        max_per = book.index(max_val)

Submission status: Wrong Answer

Solution code:
from sys import stdin
n, max_per = map(int, input().split())
max_val = 0
book = [0]*(n+1)
for _ in stdin.read().splitlines() :
    a, v = map(int, _.split())
    book[a] += v
    if v < 0 :
        for _2 in range(1, max_val) :
            if (max_val - _2) in book :
                max_val -= _2
                break
        max_per = book.index(max_val)
    else :
        if   book[a] < max_val : pass
        elif max_val < book[a] : max_per, max_val = a, book[a]
        elif       a < max_per : max_per = a
    print(max_per, max_val)

Submission status: Wrong Answer

Solution code:
n, q = map(int, input().split())
max_per, max_val = 0, 0
book = [0]*(n+1)
for _ in [None]*q :
    a, v = map(int, input().split())
    book[a] += v
    if v < 0 :
        for _2 in range(max_val) :
            if (max_val - _2) in book :
                max_val -= _2
                break
        max_per = book.index(max_val)
    else :
        if max_val < book[a] : max_per, max_val = a, book[a]
        elif max_val < book[a] and a < max_per : max_per = a
    print(max_per, max_val)

Submission status: Wrong Answer

Solution code:
from sys import stdin
n, max_per = map(int, input().split())
max_val = 0
book = [0]*(n+1)
for _ in stdin.read().splitlines() :
    a, v = map(int, _.split())
    book[a] += v
    if v < 0 :
        for _2 in [None]*max_val :
            max_val -= 1
            if max_val in book : break
        max_per = book.index(max_val)
    elif book[a] < max_val : pass
    elif max_val < book[a] : max_per, max_val = a, book[a]
    elif a < max_per : max_per = a
    print(max_per, max_val)

Submission status: Wrong Answer

Solution code:
from sys import stdin
n = [int(_) for _ in input().split()]
book = [0]*(n[0]+1)

max_per, max_val = [int(_) for _ in input().split()]
book[max_per] += max_val
print(max_per, max_val)

for _ in stdin.read().splitlines() :
    a = [int(_2) for _2 in _.split()]
    book[a[0]] += a[1]
    if a[1] < 0 :
        for _2 in [None]*book[a[0]] :
            if max_val in book : break
            max_val -= 1
        max_per = book.index(max_val)
    elif book[a[0]] < max_val : pass
    elif a[0] < max_per : max_per = a[0]
    elif max_val < book[a[0]] : max_per, max_val = a[0], book[a[0]]
    print(max_per, max_val)

Submission status: Wrong Answer

Solution code:

Submission status: Wrong Answer

Solution code:
import queue
n,q=map(int,input().split())
p=queue.PriorityQueue()
s=[0]*-~n
for _ in[0]*q:
 a,v=map(int,input().split())
 s[a]+=v;p.put((-s[a],a))
 while 1:
  t=p.get();print('___',t)
  if -t[0]==s[t[1]]:print(t[1],-t[0],s);p.put(t);break

Submission status: Wrong Answer

Solution code:
"""
セグメント木
"""

INF = 10 ** 20

def main():
  n, q = map(int, input().split())
  
  size = 1
  while size < n:
    size *= 2
  size = size * 2 - 1
  
  seg_tree = [(INF, 0) for _ in range(size)]
  
  def update(a, v):
    ind = (size - 1) // 2 + a
    prea, prev = seg_tree[ind]
    seg_tree[ind] = (a + 1, prev + v)

    while ind > 0:
      ind = (ind - 1) // 2
      ca1, cv1 = seg_tree[ind * 2 + 1]
      ca2, cv2 = seg_tree[ind * 2 + 2]
      if cv1 >= cv2:
        if seg_tree[ind] == (ca1, cv2): break
        seg_tree[ind] = (ca1, cv1)

      else:
        if seg_tree[ind] == (ca2, cv2): break
        seg_tree[ind] = (ca2, cv2)
        
  
  for i in range(q):
    a, v = map(int, input().split())
    update(a - 1, v)
    print(seg_tree[0][0], seg_tree[0][1])

main()

Submission status: Wrong Answer

Solution code:
n,q=map(int,raw_input().split())
x={}
for i in range(q):
    a,v=map(int,raw_input().split())
    x.setdefault(a,0)
    x[a]+=v
    print " ".join(map(str, sorted(x.items(),cmp=lambda a,b:b[1]-a[1])[0]))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin, exit
from collections import Counter


def main(readline=stdin.readline):
    n, q = (int(s) for s in readline().split())
    count = Counter()
    for i in range(q):
        a, v = (int(s) for s in readline().split())
        count[a] += v
        print(*count.most_common(1)[0])
    exit()


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin, exit


def main(readline=stdin.readline):
    n, q = (int(s) for s in readline().split())

    base = [0] * n
    midway = [(0, -1) for i in range(n//100 + 1)]

    for i in range(q):
        a, v = (int(s) for s in readline().split())
        a -= 1
        base[a] += v
        a -= a % 100

        index = value = 0
        for i, v in enumerate(base[a:a+100], 1):
            if value < v:
                value = v
                index = i

        midway[a//100] = (value, -index)
        v, i = max(midway)
        print(-i, v)
    exit()


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin, exit


def main(readline=stdin.readline):
    n, q = (int(s) for s in readline().split())

    base = [0] * n
    midway = [(0, -1) for i in range(n//100 + 1)]

    for i in range(q):
        a, v = (int(s) for s in readline().split())
        a -= 1
        base[a] += v
        a -= a % 100

        index = value = -1
        for i, v in enumerate(base[a:a+100], 1):
            if value < v:
                value = v
                index = i

        midway[a//100] = (value, -index)
        v, i = max(midway)
        print(-i, v)
    exit()


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin, exit, maxsize


def main(readline=stdin.readline):
    n, q = (int(s) for s in readline().split())

    base = [0] * n
    midway = [(1, -maxsize)] * (n//100 + 1)

    for _ in range(q):
        a, v = (int(s) for s in readline().split())
        a -= 1
        base[a] += v

        b = a - a % 100
        index = value = -maxsize
        for i, v in enumerate(base[b:b+100], 1):
            if value < v:
                value = v
                index = i
        midway[b//100] = (index, value)

        index = value = -maxsize
        for i, v in midway:
            if value < v:
                value = v
                index = i
        print(index, value)
    exit()


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin, exit, maxsize


def main(readline=stdin.readline):
    n, q = (int(s) for s in readline().split())

    base = [0] * n
    midway = [(-maxsize, 0)] * (n//1000 + 1)

    for _ in range(q):
        a, v = (int(s) for s in readline().split())
        a -= 1
        base[a] += v

        b = a - a % 1000
        index = value = -maxsize
        for i, v in enumerate(base[b:b+1000], b+1):
            if value < v:
                value = v
                index = i
        midway[(n-b)//1000] = (value, index)

        value, index = max(midway)
        print(index, value)
    exit()


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin, exit, maxsize


def main(readline=stdin.readline):
    n, q = (int(s) for s in readline().split())

    base = [0] * n
    midway = [0] * (n//1000 + 1)

    for _ in range(q):
        a, v = (int(s) for s in readline().split())
        a -= 1
        base[a] += v

        b = a - a % 1000

        index = value = -maxsize
        for i, v in enumerate(base[b:b+1000]):
            if value < v:
                index = i
                value = v
        midway[b//1000] = index

        value = index = -maxsize
        for i in midway:
            if value < base[i]:
                value = base[i]
                index = i

        print(index+1, value)
    exit()


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin, exit
from collections import Counter


def main(readline=stdin.readline):
    n, q = (int(s) for s in readline().split())

    count = Counter()
    count[1] = 0

    for _ in range(q):
        a, v = (int(s) for s in readline().split())
        count[a] += v
        print(*count.most_common(1)[0])
    exit()


if __name__ == '__main__':
    main()