Cod sursa(job #1843774)

Utilizator teo.cons98Constantin Teodor-Claudiu teo.cons98 Data 9 ianuarie 2017 12:58:20
Problema Farfurii Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.88 kb
#include<iostream>
#include<fstream>

using namespace std;

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


int main()
{
    unsigned long long n, k, primeleFarf, nrInverse = 0, s = 0;
    fin>>n>>k;
    while(k > s)
    {
        ++nrInverse;
        s += nrInverse;
    }
    ++nrInverse;
    primeleFarf = n - nrInverse;
    for(unsigned long long i = 1; i <= primeleFarf; ++i)
    {
        fout<<i<<" ";
    }
    if(k == s)
    {
        for(unsigned long long i = n; i > primeleFarf; --i)
        {
            fout<<i<<" ";
        }
    }
    else
    {
        s = s - k;
        s = n - s;
        fout<<s<<" ";
        for(unsigned long long i = n; i > s; --i)
        {
            fout<<i<<" ";
        }
        for(unsigned long long i = s - 1; i > primeleFarf; --i)
        {
            fout<<i<<" ";
        }
    }
}