强迫症的序列(牛客思维,累加)

强迫症的序列

#include<bits/stdc++.h>
using namespace std;

#define int long long

signed main(){
    int t, n;
    cin >> t;
    while(t--){
        cin >> n;
        vector<int> a(n), b(n);
        for(auto &x : a) cin >> x;
        sort(a.begin(), a.end());
        int sum = 0;
        for(int i = 1; i < n; ++i){
            b[i] = b[i-1] + a[i] - a[i-1];
            sum += b[i];
        }
        int t = a[n-1] + sum - b[n-1];
        cout << sum << " " << t <<endl;
    }
    
    return 0;
}
posted @ 2025-03-20 14:16  awei040519  阅读(11)  评论(0)    收藏  举报