forked from kothariji/competitive-programming
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTwo Sets.cpp
46 lines (42 loc) · 772 Bytes
/
Two Sets.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
#include <bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long n; cin >> n;
bool taken[n+1];
memset(taken, 0, sizeof(taken));
long long sum = 0;
long long wsum = n*(n+1)/2;
long long tnum = wsum/2;
if (wsum&1){
cout << "NO";
return 0;
}
for (long long i = n; i >= 1 && sum <= tnum; i--){
if (1 <= tnum-sum && tnum-sum <= i){
taken[wsum/2-sum]=1;
break;
}
taken[i] = 1;
sum += i;
}
cout << "YES\n";
vector<int> a, b;
for (int i = 1; i <=n; i++){
if (taken[i]){
a.push_back(i);
} else {
b.push_back(i);
}
}
cout << a.size() << "\n";
for (int u : a){
cout << u << ' ';
}
cout << "\n";
cout << b.size() << "\n";
for (int u : b){
cout << u << ' ';
}
}