Cod sursa(job #3144700)

Utilizator maryyMaria Ciutea maryy Data 10 august 2023 10:54:16
Problema Farfurii Scor 90
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.26 kb
#include <fstream>

using namespace std;
ifstream in("farfurii.in");
ofstream out("farfurii.out");
int n, k;
int v[100001];
bool Verif(int m)
{
    int x=n, s=0;
    while(x>0)
    {
        s+=m;
        if(s>k)
        {
            return 0;
        }
        m--;
        x--;
    }
    return 1;
}
int main()
{
    in>>n>>k;
    int st=1, dr=n, mijl, r;
    while(r*(r-1)/2<k)
    {
        r++;
    }
    //out<<r<<endl;
    for(int i=1; i<=n-r; i++)
    {
        out<<i<<" ";
    }
    int rest=r*(r-1)/2-k;
    out<<n-rest<<" ";
    for(int i=n; i>=n-r; i--)
    {
        if(i!=(n-rest))
        {
            out<<i<<" ";
        }
    }
    //
//    int cop=r, con=n, cnt=n-r-1;
//    while(k>0)
//    {
//        v[n-cop]=con;
//        k-=cop;
//        cop--;
//        con--;
//        if(cop==1 && k>1)
//        {
//            while(k>1)
//            {
//                cop=2;
//                v[cnt]=con;
//                con--;
//                cnt--;
//                k-=2;
//            }
//            cop=1;
//        }
//    }
//    for(int i=1; i<=cnt; i++)
//    {
//        v[i]=i;
//    }
//    v[n]=cnt+1;
//    for(int i=1; i<=n; i++)
//    {
//        out<<v[i]<<" ";
//    }
}