Cod sursă (job #128406)

Utilizator avatar deliadrg Delia Drg deliadrg IP ascuns
Problemă SCV (clasele 9-10) Compilator cpp | 1,18 kb
Rundă Arhiva de probleme Status evaluat
Dată 4 mar. 2015 18:30:25 Scor 90
#include <cstdio>
#include <algorithm>
using namespace std;
long long c,timp2=0,m,x,t,cantac=0,pos1,pos2,nrscv=1,p;
bool ok=false;
int main()
{
    freopen("scv.in","r",stdin);
    freopen("scv.out","w",stdout);
    scanf("%lld %lld %lld %lld\n",&c,&t,&m,&x);
    while(cantac<x && !ok)
    {
        if(cantac>=c)
        {
            pos1=(x-cantac)/(m*nrscv);
            if(cantac+(pos1*m*nrscv)<x)
                ++pos1;
            pos2=t+(x-(cantac-c+(t*nrscv*m)))/((nrscv+1)*m);
            if((pos2-t)*((nrscv+1)*m)<(x-(cantac-c+(t*nrscv*m))))
                ++pos2;
            if(pos1<=pos2)
            {
                ok=true;
                timp2+=pos1;
            }
            else
            {
                timp2+=t;
                cantac-=c;
                cantac+=(t*m*nrscv);
                ++nrscv;
            }
        }
        else
        {
            timp2+=(c-cantac)/(m*nrscv);
            cantac+=(m*nrscv*((c-cantac)/(m*nrscv)));
            if(cantac<c)
              {
                  cantac+=(m*nrscv);
                  ++timp2;
              }
        }
    }
    printf("%lld\n",timp2);
    return 0;
}