Help with a problem

I have issues wit UNQEQ problem.

According to constrains, as far as I could undersand. 6 should not be a valid input, I output “NO”, and program says it’s wrong.

Can you help me?

This is my code:
for T in range(int(input())):

N = int(input())

if (N % 4 != 0):
    print("NO")
    continue

UP   = []
DOWN = []
for i in range(0,N,2):
    if (i % 4 == 0):
        UP.append(i+1)
        DOWN.append(i+2)
    else:
        UP.append(i+2)
        DOWN.append(i+1)

print("YES")
print(*UP)
print(*DOWN)

When N % 4 == 0, then works.
Each pair must not be equal, but each list must sum the same:

I use:
1 4 5 8 9 12 → 39
2 3 6 7 10 11 → 39

3 7 11 15 19 23

But it says it’s wrong.

@ulisesaugusto1
it is said that the prefix sum till n/2 -1 index should not be equal for A and B.
for 1 4 5 8 9 12
and 2 3 6 7 10 11 for i==2 the sum is 5 for both A and B which is wrong .
plzz refer my c++ code for better understanding of the logic.

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

int main() {
	// your code goes here
	int t;
	cin>>t;
	while(t--)
	{
	    int n;
	    cin>>n;
	    vector<int> v1;
	    if(n%4==0)
	    {
	        cout<<"YES"<<endl;
	        int i=1,j=n;
	        int val=n/2;
	       // cout<<val<<endl;
	        while(val)
	        {
	            
	            //cout<<"o";
	             v1.push_back(i);
	             v1.push_back(j);
	            i++;
	            j--;
	            val=val-2;
	        }
	        sort(v1.begin(),v1.end());
	        for(int i=0;i<v1.size();i++)
	        {
	            cout<<v1[i]<<" ";
	        }
	        val=n/2;
	        v1.clear();
	        cout<<endl;
	        while(val)
	        {
	            v1.push_back(i);
	            v1.push_back(j);
	            i++;
	            j--;
	            val-=2;
	        }
	        sort(v1.begin(),v1.end());
	        for(int i=0;i<v1.size();i++)
	        {
	            cout<<v1[i]<<" ";
	        }
	    }
	    else
	    cout<<"NO";
	    cout<<endl;
	}

}

I feel weird missing that little thing, yet I’m glad you pointed it out.

Thank you so much!

1 Like