Cod sursă (job #802558)

Utilizator avatar wrunning wild running wrunning IP ascuns
Problemă SCV (clasele 9-10) Compilator cpp-32 | 0,73 kb
Rundă Arhiva de probleme Status evaluat
Dată 6 ian. 2025 19:58:00 Scor 100
#include <bits/stdc++.h>
using namespace std;
ifstream in("scv.in");
ofstream out("scv.out");

int main()
{
    int c,t,m,x,qty,nrscv=1,day=0,stock=0;//qty - quantity per day
    in>>c>>t>>m>>x;
    while (stock<x)
    {
        qty=nrscv*m;
        int needed=x-stock;
        int without=needed/qty;
        if (needed%qty>0)
            without++;
        int with=t+(needed+c-t*qty)/(qty+m);
        if ((needed-t*qty)%(qty+m)>0)
            with++;
        if (with<=without && stock>=c)
        {
            stock-=c;
            day+=t;
            stock+=qty*t;
            nrscv++;
        }
        else
        {
            day++;
            stock+=qty;
        }
    }
    out<<day;
    return 0;
}