Full Explanation | Sorting and Prefix Sum | Simple Solution
\n# Approach\n Describe your approach to solving the problem. \nWe need to first sort the numbers in the array in descending order (from largest to smallest) so
\n# Approach\n<!-- Describe your approach to solving the problem. -->\nWe need to first sort the numbers in the array in descending order (from largest to smallest) so that we can pick the biggest numbers first to maximize our score.\n\nThen create a new array that will store the cumulative sum of the numbers in the sorted array. This means that each element in the new array will be the sum of all the elements before it in the sorted array.\n\nThen loop through the sorted array, starting from the second element. For each element, it calculates the cumulative sum up to that element and stores it in the new array. If the sum is greater than 0, the code increments a counter variable.\n\nFinally, return the value of the counter variable, which represents the maximum score that can be obtained.\n\n# Complexity\n- Time complexity: O(nlogn) for sorting\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(n)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    int maxScore(vector<int>& nums) {\n        sort(nums.begin(),nums.end(),greater<int>());\n        vector<long long>prefix_sum(nums.size());\n        \n        prefix_sum[0]=nums[0];\n        long long count=0;\n        \n        if(prefix_sum[0]>0) ++count;\n        for(int i=1;i<nums.size();++i){\n            prefix_sum[i] = prefix_sum[i-1]+nums[i];\n            if(prefix_sum[i]>0) ++count;\n        }\n        \n        return count;\n    }\n};\n```
['C++']