Facebook
From Sharp Moth, 3 Years ago, written in C++.
Embed
Download Paste or View Raw
Hits: 64
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long int
  4. #define rep(p,a,b) for(int p=a;p<b;p++)
  5.       //kishor_e
  6. int main()
  7. {
  8.     ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);    
  9.  
  10. #ifndef ONLINE_JUDGE
  11.     freopen("input.txt","r",stdin);
  12.     freopen("output.txt","w",stdout);
  13. #endif
  14.     int t,n,a[n],sum = 0;
  15.     cin>>t;
  16.     while(t--){
  17.         cin>>n;
  18.         rep(i,0,n){
  19.         cin>>a[i];}
  20.     }
  21.     sort(a,a+n);
  22.     for(int i=1;i<n;i++){
  23.             sum+= abs(a[i] - a[i-1]);
  24.         }
  25.     cout<<sum<<"n";
  26. }
  27.