Cod sursa(job #2964218)

Utilizator Chris_BlackBlaga Cristian Chris_Black Data 12 ianuarie 2023 17:32:42
Problema Farfurii Scor 80
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.57 kb
#include <fstream>

using namespace std;
ifstream cin("farfurii.in");
ofstream cout("farfurii.out");
int n,k;
///O abordare greedy
int comb(int x)
{return x*(x-1)/2;}
void solve(int base,int n,int k)
{
    if(k==0)
    {
        for(int j=1;j<=n;++j)
            cout<<base+j<<' ';
        return;
    }
    int i = 1,j;
    while(comb(i)<k)
        i++;
    for(int j=1; j <= n - i; ++j)
        cout<<base + j<<' ';
    solve(base + n - i + 1,i-1,k-(i-1));
    cout<<base + n - i + 1 <<' ';
}
int main()
{
    cin>>n>>k;
    solve(0,n,k);
    return 0;
}