#include #define MIN(a, b) ((a)>(b)? (b): (a)) using namespace std; int calc(int a, int b, int c, int d, int e) { int cnt = 0; int i; for (i = 0; i < e; i += (a + b)) { int t_stt = i; int t_end = MIN(i + a, e); // t_stt <= t < t_end の範囲について、 // ロボット1は必ず動いている。ロボット2が動いているのが何秒間かを求める int t_stt_r = t_stt % (c + d); int tmp = t_end - (t_stt - t_stt_r); int cnt0 = tmp / (c + d) * c; int cnt1 = MIN(tmp % (c + d), c); int cnttmp = cnt0 + cnt1 - MIN(t_stt_r, c); cnt += cnttmp; } return cnt; } int main() { int a, b, c, d, e; scanf("%d%d%d%d%d", &a, &b, &c, &d, &e); int lim = (a + b)*(c + d); int ans = 0; if (e > lim) { int ans0 = calc(a, b, c, d, lim); ans += ans0 * (e / lim); e %= lim; } ans += calc(a, b, c, d, e); printf("%d\n", ans); return 0; }