---
# System prepended metadata

title: 2587. Rearrange Array to Maximize Prefix Score
tags: [Leetcode, Medium, Greedy]

---

# 2587. Rearrange Array to Maximize Prefix Score
###### tags: `Leetcode` `Medium` `Greedy`
Link: https://leetcode.com/problems/rearrange-array-to-maximize-prefix-score/description/
## 思路
把nums从大到小排
prefix score肯定是最大的
## Code
```python=
class Solution:
    def maxScore(self, nums: List[int]) -> int:
        nums.sort(reverse=True)
        ans = currSum = 0
        for num in nums:
            currSum += num
            if currSum > 0: ans += 1
            else: break
        return ans
```