Posted on

Description

Submission

class Solution {
public:
    int maxSatisfied(vector<int>& customers, vector<int>& grumpy, int X) {

        int sub = 0, total = 0, totalGrumpy = 0;
        for(int i = 0; i < X; ++i) {
            int tmp = customers[i] * grumpy[i];
            sub += tmp;
            totalGrumpy += tmp;
            total += customers[i];
        }

        int maxSub = sub;

        for(int l = 0, r = X; r < grumpy.size(); ++l, ++r) {
            sub -= customers[l] * grumpy[l];
            int tmp = customers[r] * grumpy[r];
            sub += tmp;
            totalGrumpy += tmp;
            total += customers[r];
            if(sub > maxSub) maxSub = sub;
        }

        return total - totalGrumpy + maxSub;
    }
};

		

Leave a Reply

Your email address will not be published. Required fields are marked *