Closing the Tweets

Can u please show me the error my code is working fine in DEV CPP compiler but show run time error in the CODECHEF’s compiler while doing custom run…

Closing the Tweets

#include
using namespace std;

int main() {
// your code goes here
int N,K; int sum=0;
cin>>N>>K;
int arr[N]={0};
for(int i=0;i<K;i++)
{
string s;
cin>>s;
if(s==“CLICK”)
{
int n;
cin>>n;
if(arr[n]==0)
arr[n]=1;
else
arr[n]=0;
for(int i=0;i<K;i++)
sum+=arr[i];
cout<<sum<<endl;
sum=0;
}
else{
for(int i=0;i<K;i++)
arr[i]=0;
for(int i=0;i<K;i++)
sum+=arr[i];
cout<<sum<<endl;
sum=0;
}
}
return 0;
}

You are accessing a[n] which results in out of bounds error . So , replace it with a[n-1]

Thanks i will try this!!!