Language: C

int main(void){
	int i,x,n,q,a,v,aaa=0,vvv=0,vv[9000],f[1000001],prev[1000001],next[1000001];
	scanf("%d %d",&n,&q);
	for(i=0;i<=n;i++){f[i]=0;prev[i]=0;next[i]=0;}
	for(i=0;i<9000;i++)vv[i]=0;

	for(;q>0;q--){
		scanf("%d %d",&a,&v);

		x=f[a];
		printf("%d\n",x);

		if(x>0){
			if(vv[x]==a){
				if(next[a]>0){vv[x]=next[a];}
				else vv[x]=0;
			}
			next[prev[a]]=next[a];
			prev[next[a]]=prev[a];
			prev[0]=0;next[0]=0;
		}

		f[a]+=v;x+=v;
		
		if(x>0){
			if(a<vv[x] || vv[x]==0){
				prev[a]=0;
				next[a]=vv[x];
				prev[vv[x]]=a;
				prev[0]=0;
				vv[x]=a;
			}
			else{
				i=vv[x];
				while(a>next[i] && next[i]>0){fprintf(stderr,"%d\n",i);i=next[i];assert(i>0);}
				prev[a]=i;
				next[a]=next[i];
				prev[next[i]]=a;
				next[i]=a;
				prev[0]=0;
			}
		}else{prev[a]=0;next[a]=0;}

		if(v>0){if(x>vvv || (x==vvv && a<aaa)){vvv=x;aaa=a;}}
		else if(a==aaa){
			/*for(i=vvv; vv[i]<1 && i>0 ;i--){assert(i>0 && i<9000);}
			vvv=i;
			aaa=vv[i];*/
		}

		printf("%d %d\n",aaa,vvv);
	}
	return 0;
}

Compiler output:
main.c: In function 'main':
main.c:3:9: error: implicit declaration of function 'scanf' [-Wimplicit-function-declaration]
    3 |         scanf("%d %d",&n,&q);
      |         ^~~~~
main.c:1:1: note: include '<stdio.h>' or provide a declaration of 'scanf'
  +++ |+#include <stdio.h>
    1 | int main(void){
main.c:3:9: warning: incompatible implicit declaration of built-in function 'scanf' [-Wbuiltin-declaration-mismatch]
    3 |         scanf("%d %d",&n,&q);
      |         ^~~~~
main.c:3:9: note: include '<stdio.h>' or provide a declaration of 'scanf'
main.c:11:17: error: implicit declaration of function 'printf' [-Wimplicit-function-declaration]
   11 |                 printf("%d\n",x);
      |                 ^~~~~~
main.c:11:17: note: include '<stdio.h>' or provide a declaration of 'printf'
main.c:11:17: warning: incompatible implicit declaration of built-in function 'printf' [-Wbuiltin-declaration-mismatch]
main.c:11:17: note: include '<stdio.h>' or provide a declaration of 'printf'
main.c:35:63: error: implicit declaration of function 'fprintf' [-Wimplicit-function-declaration]
   35 |                                 while(a>next[i] && next[i]>0){fprintf(stderr,"%d\n",i);i=next[i];assert(i>0);}
      |                                                               ^~~~~~~
main.c:35:63: note: include '<stdio.h>' or provide a declaration of 'fprintf'
main.c:35:63: warning: incompatible implicit declaration of built-in function 'fprintf' [-Wbuiltin-declaration-mismatch]
main.c:35:63: note: include '<stdio.h>' or provide a declaration of 'fprintf'
main.c:35:71: error: 'stderr' undeclared (first use in this function)
   35 |                                 while(a>next[i] && next[i]>0){fprintf(stderr,"%d\n",i);i=next[i];assert(i>0);}
      |                                                                       ^~~~~~
main.c:35:71: note: 'stderr' is defined in header '<stdio.h>'; this is probably fixable by adding '#include <stdio.h>'
main.c:35:71: note: each undeclared identifier is reported only once for each function it appears in
main.c:35:98: error: implicit declaration of function 'assert' [-Wimplicit-function-declaration]
   35 |                                 while(a>next[i] && next[i]>0){fprintf(stderr,"%d\n",i);i=next[i];assert(i>0);}
      |                                                                                                  ^~~~~~
main.c:1:1: note: 'assert' is defined in header '<assert.h>'; this is probably fixable by adding '#include <assert.h>'
  +++ |+#include <assert.h>
    1 | int main(void){