Pagini recente » Cod sursa (job #2246579) | Cod sursa (job #885076) | Cod sursa (job #129184) | Cod sursa (job #1550876) | Cod sursa (job #173694)
Cod sursa(job #173694)
#include<stdio.h>
#define INPUT "farfurii.in"
#define OUTPUT "farfurii.out"
#define NMAX 100001
FILE *fin = fopen(INPUT, "r"), *fout = fopen(OUTPUT, "w");
long long final[ NMAX ], N, K;
void readValues()
{
fscanf(fin, "%lld %lld", &N, &K);
}
void printSolution()
{
for(long i = 1; i <= N; ++i)
fprintf(fout, "%lld ", final[ i ]);
fprintf(fout, "\n");
}
void solveFunction()
{
long long prod, cont, rest, nrNum, ind, maxim;
prod = 1;
cont = 1;
while(prod <= K)
{
prod = cont * (cont + 1) / 2;
++cont;
}
--cont;
--cont;
prod = cont * (cont + 1) / 2;
rest = K - prod;
nrNum = N - cont - 1;
if(rest)
--nrNum;
for(long long i = 1; i <= nrNum; ++i)
final[ i ] = i;
ind = cont + 1 - rest;
if(rest)
final[ nrNum + 1 ] = nrNum + ind + 1;
maxim = N;
for(long long i = nrNum + 2; i <= N - ind; ++i)
{
final[ i ] = maxim;
--maxim;
}
maxim = nrNum + ind;
for(long long i = N - ind + 1; i <= N; ++i)
{
final[ i ] = maxim;
--maxim;
}
printSolution();
}
int main()
{
readValues();
solveFunction();
fclose(fin);
fclose(fout);
return 0;
}