Cod sursă (job #561675)

Utilizator avatar pofian abc abc pofian IP ascuns
Problemă SCV (clasele 9-10) Compilator cpp | 0,70 kb
Rundă Arhiva de probleme Status evaluat
Dată 30 iul. 2020 11:38:59 Scor 100
#include <fstream>
using namespace std;
ifstream fin ("scv.in");
ofstream fout("scv.out");
int c,t,m,x,productie;
int mats,zile,f,g,h;

int ceiling(int p,int q)
{
    if(p<0)
        return 0;
    return p/q+bool(p%q);
}

int main()
{
    fin>>c>>t>>m>>x;
    fin.close();
    f=min(c,x);
    productie=m;
    h=c/m;
    while(mats<x)
    {
        g=ceiling(f-mats,productie);
        zile+=g;
        mats+=productie*g;
        if(productie*(t+h)<x-mats)
        {
            zile+=t;
            mats+=(productie*t-c);
            productie+=m;
        }
        else
        {
            zile+=ceiling(x-mats,productie);
            mats=x;
        }
    }
    fout<<zile;
}