I know what is an SIGSEGV error as I read about it while trying to figure this out by myself. But, the main problem is I can’t figure out how its occurring in this program.Please try to help me out. I am getting the right answer on my system as its supposed to be. Just can’t get it accepted due to this runtime error.
#include<iostream>
using namespace std;
int mod(int a){
int k=0;
if(a>=0)
k=a;
else
k=-a;
return k;
}
int main(){
int t,i,n=0,news,p=0,win=2;
int p1[99],p2[99],lead[99],modLead[99];
cin>>t;
for(i=0;i<t;i++){
cin>>p1[i];
cin>>p2[i];
n=n+p1[i]-p2[i];
lead[i]=n;
modLead[i]=mod(lead[i]);
}
news= modLead[0];
for(i=1;i<t;i++){
if(modLead[i]>news){
news=modLead[i];
p=i;
}
}
if(modLead[p]>0)
win=1;
cout<<win<<" "<<modLead[p];
return 0;
}