Why is it giving wrong answer though running correctly for every custom input

My issue

My code

#include <iostream>
#include <bits/stdc++.h>
using namespace std;

int main() {
int t,i,j;
cin>>t;
int a[t][2];
for(i=0;i<t;i++){
    for(j=0;j<2;j++)
    
    cin>>a[i][j];
}
int d1=0,d2=0,k1=0,k2=0;
for(i=0;i<t;i++){
    if (a[i][0]>a[i][1]){
        d1=a[i][0]-a[i][1];
       k1=max(d1,k1);
        
    }
    else {
        d2=a[i][1]-a[i][0];
       k2=max(d2,k2);
        
    }
}
if(k1>k2){
    cout<<1<<" "<<k1<<endl;
     
}
  else{ 
        cout<<2<<" "<<k2<<endl;
    
    
}

	return 0;
}

Problem Link: TLG Problem - CodeChef

@bake06cake
The thing u r missing is that the score of the previous rounds are keep adding up in the next rounds .
I have corrected it in your code hope u will get it.

include
include <bits/stdc++.h>
using namespace std;

int main() {
int t,i,j;
cin>>t;
int a[t][2];
for(i=0;i<t;i++){
for(j=0;j<2;j++)
cin>>a[i][j];
}
int d1=0,d2=0,k1=0,k2=0;
for(i=0;i<t;i++){
if(i<t-1)
{
a[i+1][1]=a[i+1][1]+a[i][1];
a[i+1][0]=a[i+1][0]+a[i][0];
}
if (a[i][0]>a[i][1]){
d1=a[i][0]-a[i][1];
k1=max(d1,k1);

}
else {
    d2=a[i][1]-a[i][0];
   k2=max(d2,k2);
    
}

}
if(k1>k2){
cout<<1<<" "<<k1<<endl;

}
else{
cout<<2<<" "<<k2<<endl;

}

return 0;

}

1 Like