#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
#define int long long
#define endl '\n'
int n;
int a[N];
void solve(){
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
}
sort(a+1,a+n+1);
int ans=0;
for(int i=2;i<=n;i++){
ans+=a[i]-a[i-1];
}
cout<<ans<<endl;
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int t=1;
cin>>t;
while(t--) solve();
return 0;
}
A. Sasha and the Beautiful Array(贪心)
最新推荐文章于 2024-07-13 13:36:16 发布