#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 count=0,i,cost,sum=p; for(i=p;i>=m;i=p-d) { cost=p-d; sum=sum+i; if(cost<=s) { count++; p=i; } } for(i=p;i>=0;i=p-d) { cost=p-d; sum=sum+m; if(sum<=s) { count++; p=i; } } 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; }