Cod sursa(job #2916735)

Utilizator AlexandruBenescuAlexandru Benescu AlexandruBenescu Data 31 iulie 2022 23:55:54
Problema Farfurii Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.44 kb
#include <bits/stdc++.h>
using namespace std;
ifstream fin("farfurii.in");
ofstream fout("farfurii.out");
int main(){
  long long n, k, x, i;
  fin >> n >> k;
  x = 1;
  while (x * (x + 1) / 2 <= k)
    x++;
  for (i = 1; i <= n - x - 1; i++)
    fout << i << " ";
  fout << n - x * (x + 1) / 2 + k << " ";
  for (i = n; i >= n - x; i--)
    if (i != n - x * (x + 1) / 2 + k)
      fout << i << " ";
  fout << "\n";
  return 0;
}