-
Notifications
You must be signed in to change notification settings - Fork 0
/
1343B-Balanced Array.cpp
52 lines (40 loc) · 1.01 KB
/
1343B-Balanced Array.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <bits/stdc++.h>
using namespace std;
int main(){// constructive algorithm
int t{0};
cin >> t;
while(t--){
int sum{0}, sum2{0};
int n{0};
cin>> n;
vector<int>num;
num.push_back(2);
if(n%4 != 0){
cout << "NO\n";
}
else{
cout << "Yes\n";
for(int i = 1; i<=n; i++){
if(i%2==0){
num.push_back(i);
}
}
for(int i = 1; i<=n; i++){
if(i%2!=0){
num.push_back(i);
sum +=i;
}
}
for(int i = 1; i<=num.size()/2; i++){
sum2+=num[i];
}
int c = sum2-sum;
int lastnum = num.back();
num.back() = c+lastnum;
for(int i = 1; i<=n; i++){
cout << num[i] << " ";
}
}
}
return 0;
}