(51ms) PriorityQueue
ApproachPriorityQueueComplexityCodeOr like this:
# Approach
PriorityQueue
# Complexity
![image.png](https://assets.leetcode.com/users/images/0492f218-9271-4575-83dc-63a39e4273ec_1744190605.3366597.png)
# Code
```kotlin []
class Solution {
    fun maxScore(nums: IntArray): Int {
        var sum = 0L
        val pq = PriorityQueue<Int> { a,b -> b-a}
        for (N in nums)
            if (N>0) sum += N
            else if (N<0) pq.add(N)
        if (sum==0L) return 0
        var rez = nums.size - pq.size
        while (pq.isNotEmpty()) {
            sum += pq.poll()
            if (sum>0L) rez++ else break
        }
        return rez
    }
}
```
# Or like this:
```
class Solution {
    fun maxScore(nums: IntArray): Int {
        var sum = 0L
        val pq = PriorityQueue<Int> { a,b -> b-a}
        for (N in nums)
            if (N>0) sum += N
            else pq.add(N)
        var rez = nums.size - pq.size
        while (pq.isNotEmpty()) {
            sum += pq.poll()
            if (sum>0L) rez++ else break
        }
        return rez
    }
}
```
['Kotlin']