Cod sursa(job #2904473)

Utilizator Alexandru_PotangaPotanga Alexandru Alin Alexandru_Potanga Data 17 mai 2022 23:43:37
Problema Farfurii Scor 90
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.52 kb
#include <fstream>
using namespace std;
ifstream f("farfurii.in");
ofstream g("farfurii.out");
int main()
{

    int n, k, desc;
    f >> n >> k ;

    for(desc = 0 ; desc*(desc + 1) / 2 < k; desc++){}

    for(int asc = 1; asc < n - desc; asc++)
    {
        g << asc << " ";
    }

    int complement = n + k - desc * (desc + 1)/2;
    g << complement << " ";

    for(int rest = n; rest >= n - desc; rest--)
    {
        if(rest != complement)
            g << rest << " ";
    }

    return 0;
}