fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. const int Mod=1e9+7;
  5. const ll INF = 10000000000000;
  6. const int N = 1e6+7;
  7.  
  8. void solve() {
  9. int n;
  10. cin >> n;
  11. vector<int> a(n);
  12. for(int i=0;i<n;i++) cin >> a[i];
  13. sort(a.begin(),a.end());
  14. ll score = 0;
  15. int mi=a[0],ma=a[n-1];
  16. for(int i=1;i<n;i++){
  17. score+=ma-mi;
  18. }
  19. cout << score << '\n';
  20. }
  21. int main(){
  22. ios::sync_with_stdio(false);
  23. cin.tie(nullptr);
  24.  
  25. int t;
  26. cin >> t;
  27. while (t--) solve();
  28.  
  29. return 0;
  30. }
  31.  
Success #stdin #stdout 0.01s 5288KB
stdin
3
1
69
3
7 6 5
5
1 1 1 2 2
stdout
0
4
4