#include using namespace std; int howManyGames(int p, int d, int m, int s) { // Return the number of games you can buy // m = min game price // p = starting game price // d = successive reduction of each game price vector priceList; int currentPrice = p; while (currentPrice > m){ priceList.push_back(currentPrice); if (currentPrice - d < m) currentPrice = m; else currentPrice -= d; } priceList.push_back(m); int count = 0; int totalCost = 0; int costIndex = 0; while (totalCost < s) { currentPrice = costIndex < priceList.size()-1 ? priceList[costIndex++] : priceList[costIndex]; if (totalCost+currentPrice > s) break; totalCost += currentPrice; count++; } return count; } 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; }