Segmentation error

#include

using namespace std;

int main()
{
int t;
cin>>t;
while(t–)
{
int n ,i,flg=1;
cin>>n;
long int a[n],k,x=0;
cin>>k;
for(i=0;i<n;i++)
{
cin>>a[i];

    }
     for(i=0;i<n;i++)
    {
       if((a[i]+x)>=k)
       {
           x = (a[i]+x)-k;

       }
       else
       {
           flg=0;
           break;
       }

    }
    if(flg == 1)
        cout<<"YES"<<"\n";
    else
        cout<<"NO"<<" "<<i+1<<"\n";

}
return 0;

}

Please either format your code or link to your submission - the forum software has mangled it and it won’t compile! :slight_smile:

Also - what Problem are you trying to solve?

The problem i’m facing is that when i was running it on the code chef ide it was showing segmentation error. Accidentally click on the submit and it gets accepted, Don’t know how

link to my solution
(https://www.codechef.com/viewsolution/27966672)

1 Like

Oh, that’s because of this :slight_smile:

Got it , thanks for the help.:blush:

1 Like