#include #include #include #include #include #include #include int howManyGames(int p, int d, int m, int s) { // Return the number of games you can buy int sum = p; int c = 1; //already bought first item int k = 1; while(sum <= s && (p-(k*d)) >= m) { //c = c + 1; sum = sum + (p-(k*d)); k = k+1; c = c+1; } while(sum <= s) { c = c + 1; sum = sum + m; } if(sum > s) return c-1; else return c; } int main() { int p; int d; int m; int s; scanf("%i %i %i %i", &p, &d, &m, &s); int answer = howManyGames(p, d, m, s); printf("%d\n", answer); return 0; }