#K65682. Consume All Potions

    ID: 32252 Type: Default 1000ms 256MiB

Consume All Potions

Consume All Potions

Zoey has a sequence of potions where each potion increases or decreases her strength. In order to ensure that her strength never becomes negative, she can arrange the order in which she consumes them. Your task is to determine whether there exists an ordering such that when she takes all potions in that order, her cumulative strength remains non-negative at every step.

The optimal strategy is to consume the potions with higher (or less negative) effects first. Formally, if we denote the effects of potions as \(a_1, a_2, \dots, a_n\), we sort them in descending order, say \(b_1 \ge b_2 \ge \dots \ge b_n\), and then compute the cumulative sum \(S_k = \sum_{i=1}^{k} b_i\) for \(1 \le k \le n\). Zoey can safely drink all potions if and only if \(S_k \ge 0\) for every \(k\).

inputFormat

The input begins with an integer \(T\) (the number of test cases). Each test case consists of two lines. The first line of a test case contains an integer \(n\), the number of potions. The second line contains \(n\) integers representing the effect of each potion, separated by spaces.

outputFormat

For each test case, output a single line with the word "YES" if Zoey can consume all the potions in some order without her cumulative strength becoming negative, otherwise output "NO".

## sample
2
5
4 -1 -3 2 -2
3
10 -10 -1
YES

NO

</p>