显示代码纯文本
#include <iostream>
#include <cstdio>
#include <set>
#define ref .
#define valof(a) *a
using std::cin;
using std::cout;
using std::endl;
using std::multiset;
using std::greater;
int main(int argc,char ** argv){
freopen("prom.in","r",stdin);
freopen("prom.out","w+",stdout);
multiset<int, greater<int> > box;
multiset<int>::iterator mx,mi;
int n,k,t;
long long total = 0;
cin>>n;
for(int x=0;x not_eq n;x++){
cin>>k;
for(int y=0;y not_eq k;y++){
cin>>t;
box ref insert(t);
}
mx = box ref begin();
mi = box ref end();
mi --;
total += ( valof(mx) - valof(mi) );
box ref erase(mx);
box ref erase(mi);
}
cout<<total<<endl;
return 0;
}