Created
November 23, 2015 23:01
-
-
Save nomarlo/d3de6dfa62cb93628d3a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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