CSES Solutions
#1092Introductory Problems

Two Sets

View on CSES

Solution

1092-Two_Sets.cpp
1#include<bits/stdc++.h>
2using namespace std;
3#define int long long
4signed main(){
5  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
6  int n; cin>>n;
7  if((n*(n+1)/2)&1) cout<<"NO\n";
8  else{
9    vector<int> a,b;
10    int x=n*(n+1)/4;
11    for(int i=n;i>=1;--i){
12      if(x>=i){
13        a.emplace_back(i);
14        x-=i;
15      }else b.emplace_back(i);
16    }
17    cout<<"YES\n";
18    cout<<(int)a.size()<<'\n';
19    for(auto&x:a) cout<<x<<" ";
20    cout<<'\n';
21    cout<<(int)b.size()<<'\n';
22    for(auto&x:b) cout<<x<<" ";
23    cout<<'\n';
24  }
25  return 0;
26}

Editorial not yet generated for this problem. Run the editorial generation script to add hints and detailed explanations.