UVA 11136 - Hoax or what
题意:n天,每天收到k张小票,要准备当前有的小票中价值的Max - Min, 然后去掉这两张小票,问总的要准备的奖品价值是多少
思路:multiset去模拟即可
代码:
#include <cstdio>
#include <cstring>
#include <set>
using namespace std;
int n, k, v;
multiset<int> save;
int main() {
while (~scanf("%d", &n) && n) {
save.clear();
long long ans = 0;
for (int i = 0; i < n; i++) {
scanf("%d", &k);
for (int j = 0; j < k; j++) {
scanf("%d", &v);
save.insert(v);
}
ans += (*(--save.end()) - *save.begin());
save.erase(save.begin());
save.erase(--save.end());
}
printf("%lld\n", ans);
}
return 0;
}