Cod sursa(job #3270867)

Utilizator MihaiZ777MihaiZ MihaiZ777 Data 24 ianuarie 2025 18:57:16
Problema Farfurii Scor 30
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.85 kb
#include <fstream>
#include <iostream>
using namespace std;

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

#define MAXN 100005

int n, k;
int pivot;
int v[MAXN];

void BinSearch() {
	int lf = 0;
	int rg = n * (n - 1) / 2;

	while (lf <= rg) {
		int mid = lf + (rg - lf) / 2;
		if (mid * (mid - 1) / 2 >= k) {
			pivot = mid;
			rg = mid - 1;
		} else {
			lf = mid + 1;
		}
	}
}

int main() {
	fin >> n >> k;
	BinSearch();
	cout << pivot << ' ' << n - (pivot * (pivot - 1) / 2 - k) << '\n';
	for (int i = 0; i < n - pivot; i++) {
		v[i] = i + 1;
	}
	v[n - pivot] = n - (pivot * (pivot - 1) / 2 - k); 

	int num = n;
	for (int i = n - pivot + 1; i < n; i++) {
		if (num == n - (pivot * (pivot - 1) / 2 - k)) {
			num--;
		}
		v[i] = num;
		num--;
	}

	for (int i = 0; i < n; i++) {
		fout << v[i] << ' ';
	}
}