Cod sursa(job #2089850)

Utilizator PetrescuAlexandru Petrescu Petrescu Data 17 decembrie 2017 11:48:39
Problema Farfurii Scor 100
Compilator cpp Status done
Runda Teme Pregatire ACM Unibuc 2013 Marime 0.76 kb
#include <fstream>
#include <iostream>
#define MAX 100000

using namespace std;
int main()
{
  long long int n, k, i, st, dr, mij, j, gasit, contor;

  ifstream fin("farfurii.in");
  ofstream fout("farfurii.out");
  fin >> n >> k;
  st = 1;
  dr = MAX;
  while(st <= dr)
  {
    mij = (st + dr) / 2;
    if(mij * (mij - 1) / 2 >= k)dr = mij - 1;
    else
    {
      gasit = mij;
      st = mij + 1;
    }
  }
  for(i = 1; i <= n - gasit - 1; i++)fout << i << " ";
  fout << n - gasit + k - (gasit - 1) * gasit / 2 << " ";
  for(i = n; i >= n - gasit + 1 + (k - (gasit - 1) * gasit / 2); i--)fout << i << " ";
  for(i = n - gasit + k - gasit * (gasit - 1) / 2 - 1; i >= n - gasit; i--)fout << i << " ";
  fin.close();
  fout.close();
  return 0;
}