Pagini recente »
Istoria paginii utilizator/sclipicici
|
Istoria paginii utilizator/polonia
|
Istoria paginii utilizator/bia0ca
|
Istoria paginii utilizator/cristinica
|
Cod sursă (job #710028)
Cod sursă (job
#710028)
#include <fstream>
#define L 5e6 + 5
#define FAIL L + 1
using namespace std;
ifstream cin("scv.in" );
ofstream cout("scv.out" );
long long upd, timpscv, total, x, t, currentSCV, m, nrscv;
long long tmin;
int state;
long long fi();
void fct() {
if (t > L) {
state = 6;
}
tmin = min(tmin, fi());
state = 2;
}
void done() {
if (upd <= m) {
m -= upd;
state = 5;
return;
}
long long deltaTime = (upd - m + currentSCV * total - 1)
/ (currentSCV * total);
t += deltaTime;
m += deltaTime * currentSCV * total;
if (t > L) {
state = 6;
} else {
m -= upd;
state = 5;
}
}
long long fi() {
if (x <= m) {
return t;
}
long long deltaTime = (x - m + currentSCV * total - 1)/(currentSCV * total);
if (t + deltaTime > L) {
return L;
} else {
return t + deltaTime;
}
}
void scv() {
m += currentSCV * total * timpscv;
t += timpscv;
if (t > L) {
state = 6;
} else {
currentSCV++;
state = 1;
}
}
int main(){
cin >> upd >> timpscv >> total >> x;
t = m = 0;
currentSCV = 1;
state = 1;
tmin = L;
int iter = L;
while (t < tmin && state != 6 && iter) {
switch (state) {
case 1:
fct();
break;
case 2:
done();
break;
case 5:
scv();
break;
}
iter--;
}
cout << tmin << "\n";
return 0;
}