Cod sursa(job #2902196)
Utilizator | Data | 15 mai 2022 20:39:12 | |
---|---|---|---|
Problema | Farfurii | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva de probleme | Marime | 0.53 kb |
#include <fstream>
using namespace std;
ifstream in("farfurii.in");
ofstream out("farfurii.out");
int main()
{
long long n, k, j, i, l, x;
in>>n>>k;
for(i = 1; i*(i+1)/2 <= k; i++);
x = i;
if(x*(x-1)/2 == k) {
for(j = 1; j <= n-x; j++) out<<j<<" ";
for(l = n; l >= n-x+1; l--) out<<l<<" ";
}
else {
for(j = 1; j <= n-x-1; j++) out<<j<<" ";
out<<n-x*(x+1)/2 + k<<" ";
for(l = n; l >= n-x+1; l--)
if(l > n-x*(x+1)/2 + k) out<<l<<" ";
else out<<l-1<<" ";
}
return 0;
}