Cod sursa(job #1017548)

Utilizator AlexandruValeanuAlexandru Valeanu AlexandruValeanu Data 27 octombrie 2013 21:37:11
Problema Farfurii Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.52 kb
#include <iostream>
#include <fstream>

using namespace std;

long long N, M, K;

int main()
{
    ifstream f("farfurii.in");
    ofstream g("farfurii.out");

    f >> N >> K;

    while ( M * ( M + 1 ) / 2 < K ) M++;

    for ( int i = 1; i <= N - M - 1; ++i )
            g << i << " ";

    int x = M * ( M + 1 ) / 2 - K;

    g << N - x << " ";

    for ( int j = N; j >= N - M; --j )
            if ( j != N - x )
                    g << j << " ";

    f.close();
    g.close();

    return 0;
}