Cod sursă (job #329749)

Utilizator avatar DanD David Dan DanD IP ascuns
Problemă SCV (clasele 9-10) Compilator cpp | 0,79 kb
Rundă Arhiva de probleme Status evaluat
Dată 9 dec. 2017 20:22:36 Scor 100
#include <iostream>
#include  <fstream>
using namespace std;
ifstream in ("scv.in");
ofstream out("scv.out");
int impa(int a,int b)
{
    if(a%b==0)
        return a/b;
    else
        return a/b+1;
}
int main()
{
int costp,timpp,colect,target,t=0,scv=1,s=0,tprof,deltat,tfinish;
in>>costp>>timpp>>colect>>target;
tprof=timpp+impa(costp,colect);
tfinish=impa(target,scv*colect);
while(tprof<tfinish)
{
    if(costp<=s)
    {
        t+=timpp;
        target+=costp;
        target-=scv*colect*timpp;
        s+=timpp*scv*colect-costp;
        scv++;
    }
    else
    {
        deltat=impa(costp-s,scv*colect);
        t+=deltat;
        target-=deltat*scv*colect;
        s+=deltat*scv*colect;
    }
    tfinish=impa(target,scv*colect);
}
out<<t+tfinish;
    return 0;
}