leetcode

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

1402.cpp (336B)


      1 class Solution {
      2   public:
      3     int maxSatisfaction(vector<int> &satisf) {
      4         sort(satisf.begin(), satisf.end());
      5         if (satisf.back() <= 0) return 0;
      6 
      7         int j = satisf.size() - 1, crnt = 0, sum = 0, res = 0;
      8         for (; j >= 0; j--)
      9             res = max(res, crnt += sum += satisf[j]);
     10 
     11         return res;
     12     }
     13 };