#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=0,flag=0,count=0;while(p>m) { sum+=p; p=p-d; count++; if(sum>s){ flag=1; count--; break; } } if(flag==0){ while(sum<=s){ sum+=m; count++; } count--; } return count; } 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; }