Cod sursa(job #2093462)

Utilizator laurageorgescuLaura Georgescu laurageorgescu Data 23 decembrie 2017 18:42:37
Problema Farfurii Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.63 kb
#include <fstream>
#include <cmath>

using namespace std;

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

const int nmax = 1e5;

bool f[nmax + 1];

int main () {
    int n;
    long long k;

    fin >> n >> k;

    int p = sqrt(2 * k);
    if (1LL * p * (p + 1) / 2 <= k) {
        ++ p;
    }

    for (int i = 1; i <= n - p - 1; ++ i) {
        fout << i << " ";
        f[ i ] = 1;
    }

    int x = k - 1LL * p * (p - 1) / 2 + (n - p);
    fout << x << " ";
    f[ x ] = 1;

    for (int i = n; i > 0; -- i) {
        if (f[ i ] == 0)
            fout << i << " ";
    }

    fin.close();
    fout.close();
    return 0;
}