UVa11136 Hoax or what
模拟水题.熟悉一下multiset的用法.
1 #include <cstdio> 2 #include <cstring> 3 #include <iostream> 4 #include <set> 5 using namespace std; 6 7 int N, K; 8 multiset<int> S; 9 10 int main() 11 { 12 multiset<int>::iterator mx, mn; 13 while(cin>>N, N) 14 { 15 long long ans = 0;S.clear(); 16 for(int i = 1, x; i <= N; i++) 17 { 18 cin>>K; 19 for(int j = 1; j <= K; j++) scanf("%d", &x), S.insert(x); 20 mn = S.begin(); 21 mx = S.end(), mx--; 22 ans += (*mx - *mn); 23 S.erase(mx), S.erase(mn); 24 } 25 cout<<ans<<endl; 26 } 27 return 0; 28 }