#include<bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
/*
min
-1 -2 -3 100 200 300
// -1 8 -2 0
-4 -5 97 197 297
-9 92 192 292
83 183 283
182 364
有负数 找最小 减掉 全正加
*/
int t;
cin >> t;
while(t--){
int n;
cin >> n;
long long a[500010]={0};
for(int i = 1; i <= n;i++){
cin >> a[i];
}
sort(a+1,a+1+n);
//所有小于0的,全加一遍,大于 0 的只加一次
long long sum = 0;
for(int i = 1; i <= n; i++){
a[i] += sum;
if(a[i] < 0){
sum += a[i];
}
else {
a[i+1] += a[i] ;
}
}
cout << a[n] << endl;
}
return 0;
}
全部评论
(0) 回帖