Cod sursa(job #419773)

Utilizator mgntMarius B mgnt Data 17 martie 2010 22:52:35
Problema Farfurii Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.54 kb
#include <iostream>
#include <fstream>
using namespace std;
int
main() {
  int n, i, j, t;
  long long int k, c;
  ifstream is("farfurii.in");
  ofstream os("farfurii.out");
  is>>n>>k;
  if(0==k) {
    for(i=1; n>=i; ++i) { os<<' '<<i; }
  } else {
    i=2; c=1;
    while (k>c) { c+=i; ++i; }
    for (j=1; n-i>=j; ++j) { os<<' '<<j; }
    if (k==c) {
      for(j=n; n-i<j; --j) { os<<' '<<j; }
    } else {
      t=n-(c-k);
      os<<' '<<t;
      for(j=n; n-i<j; --j) {
        if (j!=t) { os<<' '<<j; }
      }
    }
  }
  os<<endl;
  return 0;
}