Cod sursă (job #819724)

Utilizator avatar Sbora_David Sbora Ioan-David Sbora_David IP ascuns
Problemă SCV (clasele 9-10) Compilator cpp-32 | 1,09 kb
Rundă antrenament1 Status evaluat
Dată 9 apr. 2025 12:20:48 Scor 100
#include <bits/stdc++.h>

using namespace std;
ifstream fin("scv.in");
ofstream fout("scv.out");
int cost, timp, total, x;

int main()
{
    fin >> cost >> timp >> total >> x;
    int ziCurent = 0, cntSCV = 1, curentStrans = 0;
    while(1) {
        int ziRem = (ceil)(1.0 * (x - curentStrans) / (total * cntSCV));
        int tmpFara = ziCurent + ziRem; ///daca nu mai construiesc vreun scv
        int need = 0;
        if(curentStrans < cost) need = (ceil)(1.0 * (cost - curentStrans) / (total * cntSCV)); ///cat timp mai am nevoie sa mai fac un scv
        int nouStrans = curentStrans - cost + timp * cntSCV * total + need * cntSCV * total;
        int newSCV = cntSCV + 1;
        int tmpCu = ziCurent + need + timp + (floor)(1.0 * (x - nouStrans) / (total * newSCV)); ///cat mi ar lua daca as mai avea un scv + timpu de mi o luat sa l construiesc
        if(tmpFara <= tmpCu) {
            fout << tmpFara;
            return 0;
        }
        else {
            ziCurent += need + timp;
            cntSCV = newSCV, curentStrans = nouStrans;
        }
    }

    return 0;
}