Pagini recente » Borderou de evaluare (job #2014716) | Cod sursa (job #1403505) | Cod sursa (job #3269913) | Cod sursa (job #2658605) | Cod sursa (job #3132411)
#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 = sqrt(2 * k) + 1;
while (x * (x - 1) / 2 < k)
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;
}