Pagini recente » Cod sursa (job #3291119) | Cod sursa (job #401931) | Cod sursa (job #1307204) | Cod sursa (job #1892137) | Cod sursa (job #571906)
Cod sursa(job #571906)
Utilizator |
roots1 roots |
Data |
4 aprilie 2011 21:08:09 |
Problema |
Farfurii |
Scor |
100 |
Compilator |
cpp |
Status |
done |
Runda |
107 |
Marime |
0.57 kb |
#include <stdio.h>
int N;
int BS(long long x,int L,int R)
{
if(L<=R)
{
int M=L+(R-L)/2;
if(x>(long long)(N-M+1)*(N-M)/2) return BS(x,L,M-1);
else return BS(x,M+1,R);
}
else return R;
}
int main()
{
long long Inv;
int i,pos,x;
freopen("farfurii.in","r",stdin);
scanf("%d%lld",&N,&Inv);
pos=BS(Inv,1,N);
x=N-(long long)((N-pos+1)*(N-pos)/2-Inv);
freopen("farfurii.out","w",stdout);
for(i=1;i<pos;i++)
printf("%d ",i);
printf("%d ",x);
for(i=N;i>=pos;i--)
if(i!=x) printf("%d ",i);
printf("\n");
return 0;
}