the problem link is : CodeChef: Practical coding for everyone
i wrote a code
#include
using namespace std;
int main(){
int T;
cin>>T;
for (int k=0;k<T;k++){
int N;
cin>>N;
N=N*2;
int ar[N];
// loop 1 to take values in the array as ques 1,score,ques 2,score and goes on....
for (int i =0; i<N;i++){
cin>>ar[i];
}
int score = 0;
// loop2 begins with entire purpose of calculating the total score
for (int i=1;i<N;i=i+2){
if (ar[i-1]<=8){
score = score + ar[i];
if (i>=3){
//loop 2.1 begins here
for (int j = 0; j<i-1;j=j+2){
if (ar[j]==ar[i-1]) //chck if the ques no. has been repeated in the previous entries
{
if (ar[j+1]>ar[i]){
score = score -ar[i];
}
else {
score = score - ar[j+1];
}
}
}
} // counter a problem when only one set of entry is made in the array
} // this condition is to ensure that entire scoring is considered for scorable problems
}
cout<<score<<endl;
}
return 0;
}
but when i tried running custom inputs i got the correct output as shown in the picture
but when i tried the other run option (not with the custom inputs)
i got two things to share : First one is a segmentation fault as show in image below
And the other problem is that its just partially correct (why ??)