-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuva11136.cpp
More file actions
34 lines (26 loc) · 726 Bytes
/
uva11136.cpp
File metadata and controls
34 lines (26 loc) · 726 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include<iostream>
#include<set>
#include<string>
#include<sstream>
#include<cstdint>
using namespace std;
int main() {
int n;
while(cin >> n, n > 0) {
multiset<int> ms;
uint64_t amount=0; //needed for WA resulting from int overflow
while(n--) {
int numBills, tmp;
cin >> numBills;
while(numBills--) {
cin >> tmp;
ms.insert(tmp);
}
//Can store the iterators in a variable, erase does not invalidate
//other iterators
amount += *(prev(ms.end())) - *ms.begin();
ms.erase(ms.begin()); ms.erase(prev(ms.end()));
}
cout << amount << endl;
}
}