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:
#!/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] * (n//100 + 1)
    last = [0] * (n//10000 + 1)

    for _ in range(q):
        a, v = (int(s) for s in readline().split())

        a -= 1
        base[a] += v

        b = a - a % 100

        index = b
        value = base[b]
        end = b + 100 if b + 100 < n else n
        for i in range(b, end):
            if value < base[i]:
                value = base[i]
                index = i
        midway[b//100] = index

        c = a - a % 10000

        index = c
        value = base[c]
        for i in midway[c:c+100]:
            if value < base[i]:
                value = base[i]
                index = i
        last[c//10000] = index

        index = last[0]
        value = base[index]
        for i in last:
            if value < base[i]:
                value = base[i]
                index = i

        print(index+1, value)
    exit()


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n, q = map(int, raw_input().split())
s = {}
for i in range(q):
	a,v = map(int, raw_input().split())
	if not a in s: s[a] = v
	else: s[a] += v
	ss = sorted(s.items(),key = lambda x:x[1], reverse=True)
	if ss[0][1] > 0:
		print ss[0][0],ss[0][1]
	else:
		print 1,0

Submission status: Wrong Answer

Solution code:
n, q = map(int, raw_input().split())
N = [1]*n
s = {}
for i in range(q):
	a,v = map(int, raw_input().split())
	if N[a-1]:
		s[a] = v
		N[a-1] = 0
	else:
		s[a] += v
	ss = sorted(s.items(), key=lambda x:x[1], reverse=True)
	if ss[0][1] > 0:
		print ss[0][0],ss[0][1]
	else:
		print 1,0

Submission status: Wrong Answer

Solution code:
from collections import Counter

d = Counter()
n, q = map(int, input().split())
for i in range(q):
    a, v = map(int, input().split())
    d[a] += v
    t = d.most_common(1)
    print(t[0][0], t[0][1])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def f(): return map(int,raw_input().split())
n,q=f()
A=[0]*(n+1)
a0,b0=0,0
for _ in range(q):
  a,b=f()
  A[a]+=b
  if A[a]>b0: a0,b0=a,A[a]
  else:
    b0=max(A)
    a0=A.index(b0)
  print a0,b0

Submission status: Time Limit Exceeded

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=sorted(A,key=lambda A:[A[0],A[1]])[-1]
  print -m1,m0

Submission status: Time Limit Exceeded

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
            else:
                print x, y
                break
    else:
        if x:
            print x, y
        else:
            print k, v

Submission status: Time Limit Exceeded

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
    for index, t in enumerate(sorted(dic.items(), key=itemgetter(1,0), reverse=True)):
        if check == None:
            check = t
        elif check[1] == t[1]:
            check = t
        else:
            print check[0], check[1]
            break
    else:
        print check[0], check[1]

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

n, q = list(map(int, input().split()))
cnt = Counter()
for _ in range(q):
    a, v = list(map(int, input().split()))
    cnt[a] += v
    mx = max(cnt.values())
    if mx == 0:
        print("1 0")
    else:
        print(str(min([key for key, value in cnt.items() if value == mx])) + ' ' + str(mx))

Submission status: Time Limit Exceeded

Solution code:
n, q = list(map(int, input().split()))
cnt = [0 for _ in range(n + 1)]
for _ in range(q):
    a, v = list(map(int, input().split()))
    cnt[a] += v
    mx = max(cnt)
    if mx == 0:
        print("1 0")
    else:
        print(str(min([key for key, value in enumerate(cnt) if value == mx])) + ' ' + str(mx))

Submission status: Time Limit Exceeded

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
    else:
        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: Time Limit Exceeded

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

player = [0 for _ in xrange(n)]
for i in xrange(q):
	num,point = map(int,raw_input().split())
	player[num - 1] += point
	
	MAX = max(player)
	print player.index(MAX) + 1,MAX

Submission status: Time Limit Exceeded

Solution code:
n,q=map(int,raw_input().split())
ans=[0]*n
for i in range(q):
    a,v=map(int,raw_input().split())
    ans[a-1]+=v
    t=ans.index(max(ans))
    print t+1,ans[t]
exit()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

    if v<0:
        t=-1
    if t==-1:
        for i in ans:
            if t==-1:
                t=i
            elif ans[t]<ans[i]:
                t=i
            elif ans[t]==ans[i] and t>i:
                t=i
    print t,ans[t]
exit()

Submission status: Time Limit Exceeded

Solution code:
from collections import OrderedDict
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
    tmp = OrderedDict(sorted(data.items(), key=lambda t: t[0]))
    result = OrderedDict(sorted(tmp.items(), key=lambda t: t[1], reverse=True))
    print(*result.popitem(False))

Submission status: Time Limit Exceeded

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)})
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: Time Limit Exceeded

Solution code:
from collections import OrderedDict
n, q = [int(el) for el in input().split(' ')]
data = OrderedDict({i:0 for i in range(n,0,-1)})
for _ in range(q):
    a, v = [int(el) for el in input().split(' ')]
    data[a] += v
    result = OrderedDict(sorted(data.items(), key=lambda t: t[1], reverse=True))
    print(*result.popitem(False))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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 v < 0: result = ex_result
        else: result = max(ex_result, data[a-1])
    elif ex_index == a:
        if v > 0: result = data[a-1]
        else: result = max(data)
    index = data.index(result)+1
    print(index, result)
    ex_result = result
    ex_index = index

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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 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=liquidation(A)
	rank(A)

Submission status: Time Limit Exceeded

Solution code:
def liquidation(A):
	A.sort()#??????????????????????????????
	for i in range(len(A)):
		for j in range(i+1,len(A)):
			if A[i][1]==A[j][1]:
				A[i][0]+=A[j][0]
				del A[j]
				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)

def Rank(A):
	Max=A[0][0]
	champ=A[0][1]
	for i in range(1,len(A)):
		if A[i][0]==Max:
			champ=A[i][1]
		else:
			break
	print(champ,Max)






n,q=map(int,input().split())
A=[]
for i in range(q):
	a,v=map(int,input().split())
	A.append([v,a])#a??????????????????, v?????£??£???????????°
	A=liquidation(A)
	A.sort(reverse=True)
	#print(A)
	Rank(A)

Submission status: Time Limit Exceeded

Solution code:
n,q=map(int,input().split())
A=[0]*(n+1)#????????????????????¨????????????????????????????????????
for i in range(q):
	a,v=map(int,input().split())
	A[a]+=v
	Max=A[1]
	champ=list()
	for i in range(1,len(A)):
		if A[i]>Max:
			Max=A[i]
			champ=[]
			champ.append(i)
		elif A[i]==Max:
			champ.append(i)
	champ.sort()
	print(champ[0],Max)

Submission status: Time Limit Exceeded

Solution code:
n,q=map(int,input().split())
A=[0]*(n+1)#????????????????????¨????????????????????????????????????
for i in range(q):
	a,v=map(int,input().split())
	A[a]+=v
	Max=A[1]
	champ=list()
	Max=max(A)
	for i in range(1,len(A)):
		if Max==A[i]:
			champ.append(i)
	champ.sort()
	print(champ[0],Max)

Submission status: Time Limit Exceeded

Solution code:
import bisect

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

Submission status: Time Limit Exceeded

Solution code:
#-*- coding: utf_8 -*-

level = False
def debug(v):
    if level:
        print(v)

a = [int(x) for x in input().split()]
n, q = a[0], a[1]
memo = [0] * n

for i in range(q):
    debug(memo)
    nq = [int(x) for x in input().split()]
    a, v = nq[0] - 1, nq[1]
    memo[a] += v
    print(str(memo.index(max(memo)) + 1) + " " +  str(max(memo)))

Submission status: Time Limit Exceeded

Solution code:
#-*- coding: utf_8 -*-

a = [int(x) for x in input().split()]
n, q = a[0], a[1]
memo = [0] * n

for i in range(q):
    nq = [int(x) for x in input().split()]
    a, v = nq[0] - 1, nq[1]
    memo[a] += v
    mx = max(memo)
    print(str(memo.index(mx) + 1) + " " +  str(mx))

Submission status: Time Limit Exceeded

Solution code:
#-*- coding: utf_8 -*-

n, q = [int(x) for x in input().split(' ')]
memo = [0] * n
idx = 0

for i in range(q):
    a, v = [int(x) for x in input().split(' ')]
    a -= 1
    memo[a] += v
    if v > 0:
        if memo[idx] < memo[a]:
            idx = a
        elif memo[idx] == memo[a]:
            idx = memo.index(memo[idx])

    if v < 0:
        idx = memo.index(max(memo))

    print(idx + 1, memo[idx])

Submission status: Time Limit Exceeded

Solution code:
#-*- coding: utf_8 -*-

n, q = [int(x) for x in input().split(' ')]
memo = [0] * n
idx = 0

for i in range(q):
    a, v = [int(x) for x in input().split(' ')]
    a -= 1
    memo[a] += v
    if v > 0:
        if memo[idx] < memo[a]:
            idx = a
        elif memo[idx] == memo[a]:
            idx = memo.index(memo[idx])
    elif v < 0:
        idx = memo.index(max(memo))

    print(idx + 1, memo[idx])

Submission status: Time Limit Exceeded

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)
    if Res.count(max(Res)) == 1:
        print(Men[Res.index(max(Res))],Res[Res.index(max(Res))])
    else:
        Max_M = []
        for j in range(len(Res)):
            if Res[j] == max(Res):
                Max_M.append(Men[j])        
        print(sorted(Max_M)[0],max(Res))

Submission status: Time Limit Exceeded

Solution code:
n,q = map(int,input().split())
Men = [0] * n
for i in range(q):
    a,v = map(int,input().split())
    Men[a - 1] += v    
    print(Men.index(max(Men)) + 1,max(Men))

Submission status: Time Limit Exceeded

Solution code:
import bisect

[n,q]=map(int,raw_input().split())
A=[0 for i in range(n+1)]
B=range(1,n+1)
sep=10000000
for i in range(q):
    [a,v]=map(int,raw_input().split())
    pp=A[a]*sep+(n+1-a)
    A[a]+=v
    remind=bisect.bisect_left(B,pp)
    B.pop(remind)
    bisect.insort(B,A[a]*sep+(n+1-a))
    print n+1-B[-1]%sep,B[-1]/sep

Submission status: Time Limit Exceeded

Solution code:
import bisect

[n,q]=map(int,raw_input().split())
A=[0 for i in range(n+1)]
B=range(1,n+1)
sep=n+1
for i in range(q):
    [a,v]=map(int,raw_input().split())
    pp=A[a]*sep+(n+1-a)
    A[a]+=v
    remind=bisect.bisect_left(B,pp)
    B.pop(remind)
    bisect.insort(B,A[a]*sep+(n+1-a))
    print n+1-B[-1]%sep,B[-1]/sep

Submission status: Time Limit Exceeded

Solution code:
import bisect

[n,q]=map(int,raw_input().split())
A=[0 for i in range(n+1)]
B=range(1,n+1)
sep=n+1
for i in range(q):
    [a,v]=map(int,raw_input().split())
    pp=A[a]*sep+(n+1-a)
    A[a]+=v
    remind=bisect.bisect_left(B,pp)
    del B[remind]
    bisect.insort(B,A[a]*sep+(n+1-a))
    print n+1-B[-1]%sep,B[-1]/sep

Submission status: Time Limit Exceeded

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 list(a.values()).count(d[1])>1:
        e={}
        for i in a:
            if a[i]==d[1]:e[i]=d[1]
        print(*min(e.items(),key=lambda x:x[0]))
    else:print(*d)

Submission status: Time Limit Exceeded

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

a = [0]*n

for i in range(q):
    p,v = map(int,input().split())
    a[p-1] += v
    maxx = max(a)
    print(a.index(maxx)+1,maxx)

Submission status: Time Limit Exceeded

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

import sys
import os

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

scores = [0 for i in range(n)]
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: Time Limit Exceeded

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
    maxv = max(n)
    winner = n.index(maxv)
    print(winner, maxv)

Submission status: Time Limit Exceeded

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, winner = n[a], a
        elif n[a] == maxv:
            winner = n.index(maxv)
    print(winner, maxv)

Submission status: Time Limit Exceeded

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)
    elif n[a] > maxv:
            maxv, winner = n[a], a
    elif n[a] == maxv:
            winner = n.index(maxv)
    print(winner, maxv)

Submission status: Time Limit Exceeded

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)
    elif n[a] > maxv:
            maxv, winner = n[a], a
    elif n[a] == maxv:
            winner = min(winner, a)
    print(winner, maxv)

Submission status: Time Limit Exceeded

Solution code:
n, q = [int(_) for _ in input().split()]
book = [0 for _ in range(n+1)]
for _ in range(q) :
    a, v = [int(_2) for _2 in input().split()]
    book[a] += v
    print(book.index(max(book)), max(book))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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 v < 0 : max_per, max_val = book.index(max(book)), max(book)
    elif max_val < book[a] : max_per, max_val = a, book[a]
    elif max_val == book[a] :
        if a < max_per : max_per = a
    print(max_per, max_val)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
sample = [list(map(int, _.split())) for _ in stdin.readlines()]
book = [0] * (sample[0][0]+1)
max_per, max_val = sample[0][1], 0
for _ in sample[1:] :
    a, v = _
    book[a] += v
    if max_val < book[a] : max_per, max_val = a, book[a]
    elif max_val == book[a] and a < max_per : max_per = a
    if v < 0 :
        max_val = max(book)
        max_per = book.index(max_val)
    print(max_per, max_val)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
sample = [tuple((map(int, _.split()))) for _ in stdin.readlines()]
book = [0] * (sample[0][0]+1)
max_per, max_val = sample[0][1], 0
for _ in sample[1:] :
    a, v = _
    book[a] += v
    if max_val < book[a] : max_per, max_val = a, book[a]
    elif max_val == book[a] and a < max_per : max_per = a
    if v < 0 :
        max_val = max(book)
        max_per = book.index(max_val)
    print(max_per, max_val)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
sample = [list(map(int, _.split())) for _ in stdin.readlines()]
book = [0] * (sample[0][0]+1)
max_per, max_val = sample[0][1], 0
for _ in sample[1:] :
    a, v = _
    book[a] += v
    temp = book[a]
    if max_val < temp : max_per, max_val = a, temp
    elif max_val == temp and a < max_per : max_per = a
    if v < 0 :
        max_val = max(book)
        max_per = book.index(max_val)
    print(max_per, max_val)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
sample = stdin.readlines()
temp = [int(_) for _ in sample[0].split()]
book = [0] * (temp[0]+1)
max_per, max_val = temp[1], 0
for _ in sample[1:] :
    a, v = [int(_2) for _2 in _.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: Time Limit Exceeded

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] and a < max_per : max_per = a
    if v < 0 :
        max_val = max(book)
        max_per = book.index(max_val)
    print(max_per, max_val)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
n, q = [int(_) for _ in input().split()]
book = [0] * (n+1)
max_per, max_val = q, 0
for _ in stdin.readlines() :
    a, v = [int(_2) for _2 in _.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: Time Limit Exceeded

Solution code:
from sys import stdin
sample = stdin.readlines()
n, q = map(int, sample[0].split())
book = [0] * (n+1)
max_per, max_val = q, 0
for _ in sample[1:] :
    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: Time Limit Exceeded

Solution code:
from sys import stdin
sample = [_.strip() for _ in stdin.readlines()]
a, q = [int(_) for _ in sample[0].split()]
book = [0] * (a+1)
max_per, max_val = q, 0
for _ in sample[1:] :
    a, v = [int(_2) for _2 in _.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: Time Limit Exceeded

Solution code:
from sys import stdin
sample = [map(int, _.split()) for _ in stdin.read().splitlines()]
a, max_per = sample[0]
max_val = 0
book = [0] * (a+1)
for _ in sample[1:] :
    a, v = _
    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: Time Limit Exceeded

Solution code:
from sys import stdin
sample = stdin.read().splitlines()
a, q = [int(_) for _ in sample[0].split()]
book = [0] * (a+1)
max_per, max_val = q, 0
for _ in sample[1:] :
    a, v = [int(_2) for _2 in _.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: Time Limit Exceeded

Solution code:
from sys import stdin
sample = [map(int, (_.split())) for _ in stdin.readlines()]
a, max_per = sample[0]
max_val = 0
book = [0] * (a+1)
for _ in sample[1:] :
    a, v = _
    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: Time Limit Exceeded

Solution code:
from sys import stdin
sample = stdin.read().splitlines()
a, max_per = map(int, sample[0].split())
max_val = 0
book = [0] * (a+1)
for _ in sample[1:] :
    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: Time Limit Exceeded

Solution code:
from sys import stdin
a, max_per = map(int, input().split())
max_val = 0
book = [0] * (a+1)
for _ in stdin.readlines() :
    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: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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)
    print(max_per, max_val)

Submission status: Time Limit Exceeded

Solution code:
a, q = map(int, input().split())
max_per, max_val = q, 0
book = [0] * (a+1)
for _ in [None]*q :
    a, v = map(int, input().split())
    book[a] += v
    if v < 0 :
        max_val = max(book)
        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: Time Limit Exceeded

Solution code:
from sys import stdin
a, q = map(int, input().split())
max_per, max_val = q, 0
book = [0] * (a+1)
for _ in stdin.read().splitlines() :
    a, v = map(int, _.split())
    book[a] += v
    if v < 0 :
        max_val = max(book)
        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: Time Limit Exceeded

Solution code:
from sys import stdin
a, q = map(int, input().split())
max_per, max_val = q, 0
book = [0] * (a+1)
for _ in stdin.readlines() :
    a, v = map(int, _.split())
    book[a] += v
    if v < 0 :
        max_val = max(book)
        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: Time Limit Exceeded

Solution code:
from sys import stdin
sample = stdin.read().splitlines()
a, max_per = map(int, sample[0].split()) 
max_val = 0
book = [0] * (a+1)
for _ in sample[1:] :
    a, v = map(int, _.split())
    book[a] += v
    if v < 0 :
        max_val = max(book)
        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: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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(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: Time Limit Exceeded

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   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: Time Limit Exceeded

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: Time Limit Exceeded

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 :
        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)