Cod sursa(job #3134239)

Utilizator LazarDanielGabrielLazar Daniel-Gabriel LazarDanielGabriel Data 28 mai 2023 19:50:41
Problema Plantatie Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.67 kb
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;

ifstream fin("farfurii.in");
ofstream fout("farfurii.out");

int main()
{
    long long n, k;
    fin >> n >> k;

    long long nr = 1;
    long long x = nr * (nr - 1) / 2;
    while (x < k)
    {
        ++nr;
        x = nr * (nr - 1) / 2;
    }

    vector<int> plates;
    for (int i = 1; i <= n - nr; ++i)
        plates.push_back(i);

    plates.push_back(n - x + k);

    for (int i = n; i > n - nr; --i)
    {
        if (i != n - x + k)
            plates.push_back(i);
    }

    for (int i = 0; i < n; ++i)
        fout << plates[i] << ' ';

    return 0;
}