cses

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

commit ce65298723ac6b69799e496368c535fb130251ee
parent 7c314f720a6e1d9dd7a804b01aec1d57d37698b5
Author: superpozycja <anna@superpozycja.net>
Date:   Wed, 23 Oct 2024 23:39:38 +0200

solve two sets

Diffstat:
Aintro/two_sets.cpp | 57+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 57 insertions(+), 0 deletions(-)

diff --git a/intro/two_sets.cpp b/intro/two_sets.cpp @@ -0,0 +1,57 @@ +#include <bits/stdc++.h> + +using namespace std; + +using ui = unsigned int; +using l = long; +using ul = unsigned long; +using ll = long long; +using ull = unsigned long long; + +using vi = vector<int>; +using vui = vector<ui>; +using vl = vector<l>; +using vul = vector<ul>; +using vll = vector<ll>; +using vull = vector<ull>; + +void solve() +{ + long n; + cin >> n; + + vi a, b; + long s = n * (n+1) / 2, sa = 0; + + if (s%2) { + cout << "NO\n"; + return; + } + + for (long i = n; i > 0; i--) { + if (i > s/2 - sa) { + b.push_back(i); + } else { + sa += i; + a.push_back(i); + } + } + + cout << "YES\n"; + cout << a.size() << "\n"; + for (auto aa : a) { + cout << aa << " "; + } + cout << "\n"; + + cout << b.size() << "\n"; + for (auto bb : b) { + cout << bb << " "; + } + cout << "\n"; +} + +int main() +{ + solve(); +}