Help needed in C of div3 lunchtime

This was the question- CodeChef: Practical coding for everyone

I did this but still it was segmentation error, don’t know why.

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

int main() {
// your code goes here
int n;
cin>>n;
int num;
int sum;
vectorleft;
vectorleft_ans;
vectorright;
vectorright_ans;

for(int i=0; i<n; i++){
    cin>> num;
    sum = num*(num-1);
    sum= sum/2;
    if(sum%2!=0 || num%2!=0){
        cout<<"NO"<<endl;
    }else{
       
       for(int i=0; i<num/4; i++){
           left_ans.push_back(num-num/4+i+1);
           right_ans.push_back(num/4+i+1);
       }
       for(int j=0; j<num/4; j++){
           left_ans.push_back(j+1);
           right_ans.push_back(num/2+1+i);
       }
       
       
   
    }
for(int i=0; i<num/2; i++){
    if(i!=(num/2)-1){
       cout<<left_ans[i]<<" ";
    }else{
        cout<<left_ans[i]<<endl;
    }
}
for(int i=0; i<num/2; i++){
   cout<<right_ans[i]<<" ";
}

}



return 0;

}

You have so many syntax errors, how it compiled?
The way of vector declaration is vector<int>v

formula of finding sum is incorrect. And in the following lines you can’t access i in the second loop.

Timely reminder to please either format your code or (better!) link to your submission - the forum software has mangled it and it won’t compile! :slight_smile:

3 Likes

Thanks. I got the error btw. Anyway how to delete this post?

Just leave it - it might be useful to other people :slight_smile: