Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- int main()
- {
- long long n,k,i,ans,a;
- while(scanf("%lld",&n)&&n)
- {
- ans = 0;
- multiset<long long>multist;
- while(n--)
- {
- scanf("%lld",&k);
- for(i=1; i<=k; i++)
- {
- scanf("%lld",&a);
- multist.insert(a);
- }
- multiset<long long>::iterator mn,mx;
- mn = multist.begin();
- mx = multist.end();
- mx--;
- ans += ( *mx - *mn );
- multist.erase(mn);
- multist.erase(mx);
- }
- printf("%lld\n",ans);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment