#include int main() { int ve, me, mul, lim; scanf("%d %d %d %d", &ve, &me, &mul, &lim); int ans = 0; for (int i = ve; i >= 0; --i) { for (int j = me; j >= 0; --j) { if (mul * i > j) break; if (i + j > lim) continue; ans = (ans < i ? i : ans); } } printf("%d\n", ans); }