题目大意:超市举行促销活动,一开始箱子是空的,每天消费顾客将小票放入箱子中,一天结束后,从箱子中拿出消费最高的和最低的小票,其他留在箱子中,并且前者获得两张小票消费金额差值的奖品。问说超市一共会送出价值多少的奖品。
解题思路:用multiset模拟即可。
#include <cstdio>
#include <cstring>
#include <set>
#include <algorithm>
using namespace std;
multiset<int> g;
int main () {
int N, M, x;
while (scanf("%d", &N) == 1 && N) {
long long ret = 0;
g.clear();
for (int i = 0; i < N; i++) {
scanf("%d", &M);
for (int j = 0; j < M; j++) {
scanf("%d", &x);
g.insert(x);
}
int l = *g.begin(), r = *(--g.end());
ret += r - l;
g.erase(--g.end());
g.erase(g.begin());
}
printf("%lld\n", ret);
}
return 0;
}