Cod sursa(job #3359523)

Utilizator filipdanieloanFilip-Daniel Oancea filipdanieloan Data 29 iunie 2026 14:40:38
Problema Farfurii Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.92 kb
#include <bits/stdc++.h>
using namespace std;

#define int long long

signed main() {
#ifndef LOCAL
    cin.tie(nullptr)->sync_with_stdio(false);
    freopen("farfurii.in", "r", stdin);
    freopen("farfurii.out", "w", stdout);
#endif

    int n, k; cin >> n >> k;
    int s = 0;
    vector<int> ans;
    int backwards = n;
    bool didntWork = false;
    int point = 0;
    for (int i = 1; i <= n; ++i) {
        if (didntWork) {
            ans.push_back(backwards--);
            if (ans.back() == point)
                ans.back() = backwards--;
            continue;
        }
        int maxInversionsWithout = (n - i) * (n - i - 1) / 2;
        if (maxInversionsWithout < k) {
            didntWork = true;
            ans.push_back(i + k - maxInversionsWithout);
            point = ans.back();
            continue;
        }
        ans.push_back(i);
    }

    for (auto& i : ans) cout << i << ' ';
    cout << '\n';

    return 0;
}