Cod sursa(job #2764658)

Utilizator DragosC1Dragos DragosC1 Data 21 iulie 2021 23:09:11
Problema Farfurii Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.71 kb
#include <fstream>
#include <vector>
using namespace std;

int n;
long long k;

void read() {
    ifstream f("farfurii.in");
    f >> n >> k;
    f.close();
}

vector<int> v;

void solve() {
    int i, x = 1, y;
    while (1LL * x * (x - 1) / 2 < k)
        x++;
    for (i = 1; i <= n - x; i++)
        v.emplace_back(i);
    y = n - (1LL * x * (x - 1) / 2 - k);
    v.emplace_back(y);
    for (i = n; i >= n - x + 1; i--)
        if (i != y)
            v.emplace_back(i);
}

void output() {
    int i;
    ofstream g("farfurii.out");
    for (i = 0; i < v.size(); i++)
        g << v[i] << ' ';
    g.close();
}

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