Skip to content

Instantly share code, notes, and snippets.

@nomarlo
Created November 23, 2015 23:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nomarlo/d3de6dfa62cb93628d3a to your computer and use it in GitHub Desktop.
Save nomarlo/d3de6dfa62cb93628d3a to your computer and use it in GitHub Desktop.
#include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <sstream>
#include <map>
#include <set>
using namespace std;
/**
Recordar que el iterador iterador.end() no contiene el último dato del multiset, sino mas bien --iterador.end()
**/
multiset <int> B;
int n,k,b;
long long int res;
int main(){
scanf("%d",&n);
while(n){
res=0;
while(n--){
scanf("%d",&k);
while(k--){
scanf("%d",&b);
B.insert(b);
}
res+=(*--B.end())-*B.begin();
B.erase(--B.end());
B.erase(B.begin());
}
if(B.size())
B.clear();
cout<<res<<endl;
scanf("%d",&n);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment