Cod sursa(job #2752739)

Utilizator alexbrinzaAlexandru Brinza alexbrinza Data 19 mai 2021 12:57:23
Problema Farfurii Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.61 kb
#include <iostream>
#include <fstream>
using namespace std;

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

long long n, k, x;

void read()
{
    in >> n >> k;

    x = 1;
    while(x * (x - 1) / 2 < k) ++x;

    for(int i = 1; i <= n - x; ++i)
        out << i << " ";

    if(k == x * (x - 1) / 2)
        for(int i = n; i >= n - x + 1; --i)
            out << i << " ";
    else
    {
        int inv = x * (x - 1) / 2 - k;
        out << n - inv << " ";

        for(int i = n; i >= n - x + 1; --i)
            if(i != n - inv)
                out << i << " ";
    }
}

int main()
{
    read();
    return 0;
}