Sorting + Greedy
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
# 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```python3 []\nclass Solution:\n    def maxScore(self, nums: List[int]) -> int:\n        nev, pos = [], []\n        for num in nums:\n            if num<0:\n                nev.append(num)\n            else:\n                pos.append(num)\n\n        pos.sort(reverse=True)\n        nev.sort(reverse=True)\n\n        ans, i, j, prefixSum = 0, 0, 0, 0\n        while i<len(pos) and j<len(nev):\n            while i<len(pos):\n                prefixSum += pos[i]\n                i += 1\n                if prefixSum > 0:\n                    break\n            if prefixSum<=0:\n                return ans\n                \n            ans += 1\n\n            while j<len(nev):\n                if prefixSum+nev[j] <= 0:\n                    break\n                prefixSum += nev[j]\n                ans += 1\n                j += 1\n\n        while i<len(pos):\n            prefixSum += pos[i]\n            if prefixSum>0:\n                ans += 1\n            i += 1\n\n        return ans\n```
['Array', 'Greedy', 'Sorting', 'Prefix Sum', 'Python3']