Cod sursa(job #2104635)
| Utilizator | Data | 11 ianuarie 2018 23:18:21 | |
|---|---|---|---|
| Problema | Farfurii | Scor | 90 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.6 kb |
#include <fstream>
using namespace std;
ifstream cin("farfurii.in");
ofstream cout("farfurii.out");
const int nmax=100000;
long long n,k,i,l;
bool ap[nmax+5];
int main()
{
cin>>n>>k;
l=n;
for(i=1;i<=n;i++)
{
l--;
if(l*(l-1)/2<=k)
break;
cout<<i<<" ";
ap[i]=1;
}
int val=l*(l-1)/2;
for(int j=i;j<=n;j++)
{
if(val+j-i==k)
{
cout<<j<<" ";
ap[j]=1;
break;
}
}
for(int j=n;j>=1;j--)
if(ap[j]==0)
cout<<j<<" ";
return 0;
}
