leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

1052.cpp (473B)


      1 class Solution {
      2   public:
      3     int maxSatisfied(const vector<int> &customers, const vector<int> &grumpy, int minutes) const {
      4         const int n = size(customers);
      5         int total = 0, crnt = 0, maxi = 0;
      6 
      7         for (int i = 0; i < n; i++) {
      8             (grumpy[i] ? crnt : total) += customers[i];
      9             if (i >= minutes && grumpy[i - minutes]) crnt -= customers[i - minutes];
     10             maxi = max(maxi, crnt);
     11         }
     12 
     13         return total + maxi;
     14     }
     15 };