Pagini recente » Cod sursa (job #2931833) | Cod sursa (job #2070999) | Cod sursa (job #2125527) | Cod sursa (job #2708242) | Cod sursa (job #3132409)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("farfurii.in");
ofstream fout("farfurii.out");
class FarfuriiSolver {
private:
int n, k, x;
void calculateX() {
x = 1;
while (x * (x + 1) / 2 < k)
x++;
x++;
}
void afisMaiMiciX(int x) {
for (int i = 1; i <= n - x; i++)
fout << i << " ";
}
void afisMaiMariX(int x, int nr) {
for (int i = n; i > n - x; i--)
if (i != nr)
fout << i << " ";
}
public:
void solveProblem() {
fin >> n >> k;
calculateX();
afisMaiMiciX(x);
if (k == x * (x - 1) / 2) {
for (int i = n; i > n - x; i--)
fout << i << " ";
return;
}
int nr = n - (x * (x - 1) / 2 - k);
fout << nr << " ";
afisMaiMariX(x, nr);
}
};
int main() {
FarfuriiSolver solver;
solver.solveProblem();
return 0;
}