C++ | Sorting | Prefix Sum | Easy
ApproachRunning sum of sorted array until it becomes negative.Complexity

Time complexity: O(nlogn)


Space complexity: O(1)

Code
# Approach
Running sum of sorted array until it becomes negative.
# Complexity
- Time complexity: $$O(nlogn)$$

- Space complexity: $$O(1)$$
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```cpp []
class Solution {
public:
    int maxScore(vector<int>& nums) {
        sort(nums.begin(),nums.end());
        long runningSum = 0;
        int count=0;
        for(int i=nums.size()-1;i>=0;i--){
            runningSum+=(long)nums[i];
            if(runningSum<=0) break;
            count++;
        }
        return count;
    }
};
```
['Greedy', 'Sorting', 'Prefix Sum', 'C++']