Cod sursa(job #1533697)

Utilizator toniobFMI - Barbalau Antonio toniob Data 22 noiembrie 2015 21:19:32
Problema Farfurii Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.47 kb
#include <fstream>
#include <iostream>
using namespace std;

ifstream in("farfurii.in");
ofstream out("farfurii.out");

int n, k;

int main() {

	in >> n >> k;

	long long x = 1;
	while (x * (x-1) / 2 < k) ++x;

	long long nr = x * (x + 1) / 2 - k;

	long long y = 1;
	while(y * (y + 1) / 2 < nr) ++y;
	y--;

	for (int i = 1; i <= n - x; out << i++ << " ");
	y = n - y + 1;
	out << y << " ";
	for (int i = n; i > n - x; --i) {
		if (i != y) {
			out << i << " ";
		}
	}

	return 0;
}