Cod sursa(job #1192820)
| Utilizator | Data | 29 mai 2014 20:13:51 | |
|---|---|---|---|
| Problema | Farfurii | Scor | 90 |
| Compilator | cpp | Status | done |
| Runda | Teme Pregatire ACM Unibuc 2013 | Marime | 0.68 kb |
#include <iostream>
#include <fstream>
#include <cmath>
using namespace std;
ifstream fin("farfurii.in");
ofstream fout("farfurii.out");
#define MAX 100010
int a[MAX];
int n;
void af()
{
int i;
for(i=1;i<=n;i++)
{
fout<<a[i]<<" ";
}
fout<<"\n";
}
int main()
{
int k, x, i;
fin>>n>>k;
x=(int)sqrt(2*k);
if(x*(x+1)/2<=k)
{
x++;
}
k-=((x-1)*x/2);
int dr=0;
for(i=1;i<=n-x-1;i++)
{
a[i]=++dr;
}
int g=n-x-1;
for(i=n;!a[i];i--)
{
a[i]=++dr;
}
// af();
for(i=n-k;i>g+1;i--)
{
swap(a[i], a[i-1]);
}
af();
}
