Cod sursă (job #819596)

Utilizator avatar mihaigeorgescu Georgescu Mihai mihaigeorgescu IP ascuns
Problemă SCV (clasele 9-10) Compilator cpp-32 | 0,90 kb
Rundă antrenament1 Status evaluat
Dată 9 apr. 2025 10:04:40 Scor 20
#include <fstream>

using namespace std;
ifstream fcin("scv.in");
ofstream fout("scv.out");
int c,m,t,x;
inline int f(int val)
{
    int r=m,s=0, ok=0, poz=-1;
    for(int i=0; i<val; i++)
    {
        if(poz==i)
        {
            r+=m;
            ok=0;
        }
        s+=r;
        if(s>=x) return 1;
        if(s>=c && ok==0)
        {
            int nrz=t;
            int sum=(s-c+r*t);
            if( ((x-s)/r+1) > (x-sum)/(r+m)+nrz)
            {
                s-=c;
                poz=i+t+1;
                ok=1;
            }
        }
    }
    return 0;
}
int main()
{
    fcin>>c>>t>>m>>x;
    int st=1, dr=1e9, sol=-1;
    while(st<=dr)
    {
        int mij=(st+dr)/2;
        if(f(mij))
        {
            dr=mij-1;
            sol=mij;
        }
        else
        {
            st=mij+1;
        }
    }
    fout<<sol;
    return 0;
}