category-wise-problems

contains category wise problems(data structures, competitive) of popular platforms.

View the Project on GitHub mayankdutta/category-wise-problems

1402. Reducing dishes

implementation ```cpp class Solution { public: int maxSatisfaction(vector& arr) { sort(arr.begin(), arr.end()); if (arr.back() <= 0) return 0; int ans = 0, till = -1, sum = 0, mx = 0; for (int i = 0; i < arr.size(); i++) { mx += (arr[i] * (i + 1)); sum += arr[i]; } for (int i = 0; i < arr.size(); i++) { ans = max(ans, mx); mx -= sum; sum -= arr[i]; } return ans; } }; ``` </details>
more concise ```cpp int maxSatisfaction(vector &s) { sort(s.begin(), s.end()); int n = s.size(), res = 0, sum = 0, ans = 0; for (int i = n - 1; i >= 0; i--) { ans += sum + s[i]; sum += s[i]; res = res > ans ? res : ans; } return res; } ``` </details>