Created
January 7, 2017 01:52
-
-
Save dudelson/f0f802076a19d70b46f527faacab5f53 to your computer and use it in GitHub Desktop.
My solution for UVA 11136
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 <iostream> | |
#include <set> | |
using namespace std; | |
int n, x, k; | |
long long sum; | |
multiset<int> bills; | |
int main() { | |
while(cin >> n, n) { | |
sum = 0; | |
bills.clear(); | |
for(int nn=0; nn<n; nn++) { | |
cin >> k; | |
for(int i=0; i<k; i++) { | |
cin >> x; | |
bills.insert(x); | |
} | |
auto hit = bills.end(), lot = bills.begin(); hit--; | |
sum += (*hit)-(*lot); | |
bills.erase(hit); bills.erase(lot); | |
} | |
cout << sum << '\n'; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment