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)


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