Pagini recente »
Cod sursă (job #819654)
Cod sursă (job
#819654)
#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 + (ceil)(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;
}