set UVA 11136 Hoax or what
题意:训练指南P245
分析:set维护,查询删除最大最小值
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main(void) { int n; multiset<int> S; while (scanf ("%d", &n) == 1) { if (!n) break; S.clear (); ll ans = 0; for (int m, i=1; i<=n; ++i) { scanf ("%d", &m); for (int v, j=1; j<=m; ++j) { scanf ("%d", &v); S.insert (v); } int p1 = *(S.begin ()); int p2 = *(S.rbegin ()); ans += p2 - p1; S.erase (S.find (p1)); S.erase (S.find (p2)); } printf ("%I64d\n", ans); } return 0; }
编译人生,运行世界!