Skip to content

Instantly share code, notes, and snippets.

@dudelson
Created January 7, 2017 01:52
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 dudelson/f0f802076a19d70b46f527faacab5f53 to your computer and use it in GitHub Desktop.
Save dudelson/f0f802076a19d70b46f527faacab5f53 to your computer and use it in GitHub Desktop.
My solution for UVA 11136
#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