Pagini recente » Cod sursa (job #671457) | Cod sursa (job #1699668) | Cod sursa (job #1676731) | Cod sursa (job #1244475) | Cod sursa (job #739993)
Cod sursa(job #739993)
#include <fstream>
#include <iostream>
using namespace std;
const char infile[] = "farfurii.in";
const char outfile[] = "farfurii.out";
inline void readInput(int &N, int &K)
{
fstream fin(infile, ios::in);
fin >> N
>> K;
fin.close();
}
void solve(int N, int K, ostream& cout)
{
int minN = 1;
while(K > (minN*(minN-1)/2))
{
minN++;
}
int toSubstract = (minN*(minN-1)/2) - K;
//cout << "minN = "<< minN << "\n";
//cout << "toSubstract = "<< toSubstract << "\n";
for(int i = N; i > minN; i--)
{
cout << N - i + 1 << " ";
}
cout << N - toSubstract << " ";
for(int i = 0; i < minN; i++)
{
if( N - i != (N - toSubstract ))
cout << N - i << " ";
}
cout << "\n";
}
int main(int argc, char* argv[])
{
int N = 10;
int K = 14;
readInput(N, K);
fstream fout(outfile, ios::out);
//solve(N, K, cout);
solve(N, K, fout);
fout.close();
}