Cod sursa(job #2223894)

Utilizator caesar2001Stoica Alexandru caesar2001 Data 21 iulie 2018 23:10:58
Problema Farfurii Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.55 kb
#include <bits/stdc++.h>

using namespace std;
ifstream in("farfurii.in");
ofstream out("farfurii.out");

int main() {
    ios::sync_with_stdio(false);
    in.tie(0);
    out.tie(0);
    long long n, k, i;
    in >> n >> k;
    for(i = 0; i * (i + 1) / 2 < k; i ++);
    int consec = n - i - 1;
    for(long long j = 1; j <= consec; j ++)
        out << j << " ";
    long long dif = n - i * (i + 1) / 2 + k;
    out << dif << " ";
    for(int j = n; j > consec; j --)
        if(j != dif)
            out << j << " ";

    return 0;
}