Cod sursa(job #2643294)

Utilizator PatrickCplusplusPatrick Kristian Ondreovici PatrickCplusplus Data 19 august 2020 14:08:38
Problema Farfurii Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.67 kb
#include <bits/stdc++.h>

using namespace std;

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

int v[100005];

int main(){
    long long n, k, aux;
    fin >> n >> k;
    aux = n;
    while (1LL * aux * (aux - 1) / 2 > k) --aux;
    for (int i = 1; i <= n - aux; ++i) v[i] = i;
    for (int i = n - aux + 1, j = n; i <= n; ++i, --j) v[i] = j;
    if (1LL * aux * (aux - 1) / 2 != k){
        int diff = k - 1LL * aux * (aux - 1) / 2, elem = v[n - aux];
        swap(v[n - diff + 1], v[n - aux]);
        for (int i = n - diff + 1; i < n; ++i) v[i] = v[i + 1];
        v[n] = elem;
    }
    for (int i = 1; i <= n; ++i) fout << v[i] << " ";

}