Cod sursa(job #2904616)

Utilizator Alexandru_PotangaPotanga Alexandru Alin Alexandru_Potanga Data 18 mai 2022 00:15:25
Problema Farfurii Scor 90
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.46 kb
#include <fstream>
using namespace std;
ifstream f("farfurii.in");
ofstream g("farfurii.out");
int n, k, desc;
int main()
{
    f >> n >> k ;
    while(desc*(desc + 1) >> 1 < k)
        desc++;
    for(int asc = 1; asc < n - desc; asc++)
        g << asc << " ";
    int cop = n + k - (desc * (desc + 1)>>1);
    g << cop << " ";
    for(int rest = n; n - desc <= rest; rest--)
        if(rest != cop)
            g << rest << " ";
    return 0;
}