#include using namespace std; int howManyGames(int p, int d, int m, int s) { // Return the number of games you can buy int numGames = 0; // Number of games bool done = false; // Check unable to afford more int cost = 0; // Cost of games int subtotal; // Subtotal calculated int i = 0; // Temporary number of games while(s > cost && !done){ subtotal = cost; // if(p-i*d > m) subtotal += p-i*d; else subtotal += m; // Check that subtotal doesn't exceed dollars available if(s-subtotal >= 0){ cost = subtotal; numGames++; } else done = true; i++; } return numGames; } int main() { int p; int d; int m; int s; cin >> p >> d >> m >> s; int answer = howManyGames(p, d, m, s); cout << answer << endl; return 0; }