Explained !! EASY sorting and simulation ✅
Intuition\n Describe your first thoughts on how to solve this problem. \n- The goal is to find the maximum number of non-empty prefix subarrays where the sum of
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n- The goal is to find the maximum number of non-empty prefix subarrays where the sum of the elements is positive.\n- A prefix subarray is formed by taking the first \'i\' elements of the sorted array.\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. Sort the array in descending order:\n   - Sorting helps ensure that we are adding larger numbers first, maximizing the prefix sum.\n   \n2. Create a prefix sum array:\n   - Traverse through the sorted array and keep a running sum of the elements.\n   - If the current prefix sum is positive, increment the answer count.\n   - If the current prefix sum becomes non-positive, stop the iteration because adding smaller or negative values \n     will only decrease the sum further.\n\n3. Return the count of positive prefix sums as the final answer.\n# Complexity\n- Time complexity: O(nlogn)\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```cpp []\nclass Solution {\npublic:\n    typedef long long ll;\n    int maxScore(vector<int>& nums) {\n        ll ans=0;\n        sort(nums.begin(),nums.end(),greater<ll>());\n        ll n=nums.size();      \n        vector<ll>pre(n);\n        \n        for(ll i=0;i<n;i++){\n            if(i==0){\n                pre[i]=nums[i];\n            }else{\n                pre[i]=pre[i-1]+nums[i];\n            }\n            \n            if(pre[i]>0) ans++;\n            else break;\n        }\n        return ans;\n    }\n};\n```
['Array', 'Greedy', 'Sorting', 'Prefix Sum', 'C++']