Language: C

n, q = gets.chomp.split(" ").map{|s| s.to_i}

avs = [nil] + (1..n).map{|a| [a, 0]}
avcache = {}

max_a = 1
max_v = 0

q.times.each do
  a, v = gets.chomp.split(" ").map{|s| s.to_i}

  av0 = avs[a]
  v0 = (av0[1] += v)

  if v > 0
    avcache[a] = av0 if avcache[a].nil?
    if max_v < v0
      max_v = v0
      max_a = a
    elsif max_v == v0 && max_a > a
      max_a = a
    end
  else
    avcache.delete(a) if v0 == 0
    if max_a == a
      av1 = avcache.values.max{|a, b| a[1] <=> b[1] || b[0] <=> a[0]}
      max_a, max_v = av1
    end
  end

  #p avs
  puts [max_a, max_v].join(" ")
end

Compiler output:
main.c:1:1: warning: data definition has no type or storage class
    1 | n, q = gets.chomp.split(" ").map{|s| s.to_i}
      | ^
main.c:1:1: error: type defaults to 'int' in declaration of 'n' [-Wimplicit-int]
main.c:1:4: error: type defaults to 'int' in declaration of 'q' [-Wimplicit-int]
    1 | n, q = gets.chomp.split(" ").map{|s| s.to_i}
      |    ^
main.c:1:8: error: 'gets' undeclared here (not in a function)
    1 | n, q = gets.chomp.split(" ").map{|s| s.to_i}
      |        ^~~~
main.c:1:33: error: expected ',' or ';' before '{' token
    1 | n, q = gets.chomp.split(" ").map{|s| s.to_i}
      |                                 ^
main.c:3:1: warning: data definition has no type or storage class
    3 | avs = [nil] + (1..n).map{|a| [a, 0]}
      | ^~~
main.c:3:1: error: type defaults to 'int' in declaration of 'avs' [-Wimplicit-int]
main.c:3:7: error: expected expression before '[' token
    3 | avs = [nil] + (1..n).map{|a| [a, 0]}
      |       ^
main.c:3:8: error: 'nil' undeclared here (not in a function)
    3 | avs = [nil] + (1..n).map{|a| [a, 0]}
      |        ^~~
main.c:3:16: error: too many decimal points in number
    3 | avs = [nil] + (1..n).map{|a| [a, 0]}
      |                ^~~~
main.c:4:1: warning: data definition has no type or storage class
    4 | avcache = {}
      | ^~~~~~~
main.c:4:1: error: type defaults to 'int' in declaration of 'avcache' [-Wimplicit-int]
main.c:6:1: error: expected ',' or ';' before 'max_a'
    6 | max_a = 1
      | ^~~~~
main.c:12:3: warning: data definition has no type or storage class
   12 |   av0 = avs[a]
      |   ^~~
main.c:12:3: error: type defaults to 'int' in declaration of 'av0' [-Wimplicit-int]
main.c:12:13: error: 'a' undeclared here (not in a function)
   12 |   av0 = avs[a]
      |             ^
main.c:13:3: error: expected ',' or ';' before 'v0'
   13 |   v0 = (av0[1] += v)
      |   ^~
main.c:27:7: warning: data definition has no type or storage class
   27 |       max_a, max_v = av1
      |       ^~~~~
main.c:27:7: error: type defaults to 'int' in declaration of 'max_a' [-Wimplicit-int]
main.c:27:14: error: type defaults to 'int' in declaration of 'max_v' [-Wimplicit-int]
   27 |       max_a, max_v = av1
      |              ^~~~~
main.c:27:22: error: 'av1' undeclared here (not in a function); did you mean 'av0'?
   27 |       max_a, max_v = av1
      |                      ^~~
      |                      av0
main.c:28:5: error: expected ',' or ';' before 'end'
   28 |     end
      |     ^~~
main.c:31:4: error: invalid preprocessing directive #p
   31 |   #p avs
      |    ^