cses

solution to cses exercise problems
git clone git://git.superpozycja.net/cses
Log | Files | Refs | README

two_sets.cpp (783B)


      1 #include <bits/stdc++.h>
      2 
      3 using namespace std;
      4 
      5 using ui = unsigned int;
      6 using l = long;
      7 using ul = unsigned long;
      8 using ll = long long;
      9 using ull = unsigned long long;
     10 
     11 using vi = vector<int>;
     12 using vui = vector<ui>;
     13 using vl = vector<l>;
     14 using vul = vector<ul>;
     15 using vll = vector<ll>;
     16 using vull = vector<ull>;
     17 
     18 void solve()
     19 {
     20 	long n;
     21 	cin >> n;
     22 
     23 	vi a, b;
     24 	long s = n * (n+1) / 2, sa = 0;
     25 
     26 	if (s%2) {
     27 		cout << "NO\n";
     28 		return;
     29 	}
     30 
     31 	for (long i = n; i > 0; i--) {
     32 		if (i > s/2 - sa) {
     33 			b.push_back(i);
     34 		} else {
     35 			sa += i;
     36 			a.push_back(i);
     37 		}
     38 	}
     39 
     40 	cout << "YES\n";
     41 	cout << a.size() << "\n";
     42 	for (auto aa : a) {
     43 		cout << aa << " ";
     44 	}
     45 	cout << "\n";
     46 
     47 	cout << b.size() << "\n";
     48 	for (auto bb : b) {
     49 		cout << bb << " ";
     50 	}
     51 	cout << "\n";
     52 }
     53 
     54 int main()
     55 {
     56 	solve();
     57 }