Halloween Sale

  • + 0 comments
    int howManyGames(int p, int d, int m, int s) {
        // Return the number of games you can buy
        vector <int> x;
        int sum=0;
        for(int i=p;sum<s;i-=d){
            if(i>=m){ 
                x.push_back(i);
            }else {
                x.push_back(m);
            }      
            sum=accumulate(x.begin(),x.end(),0);
        }
        if(sum>s){
            x.pop_back();
        }
        return x.size();
    }