#include <algorithm>
#include <cstdio>
#include <cstring>
#include <set>
using namespace std;
const int maxn = 100000 + 7;
const int INF = ~0U >> 1;
typedef long long LL;
multiset<int> s;
int n, k;
int main() {
while(scanf("%d", &n) != EOF && n) {
s.clear();
int a;
LL sum = 0;
for(int i = 0; i < n; ++i) {
scanf("%d", &k);
for(int j = 0; j < k; ++j) {
scanf("%d", &a);
s.insert(a);
}
multiset<int>::iterator beg = s.begin(), en = s.end();
en--;
sum += (*en - *beg);
s.erase(beg); s.erase(en);
}
printf("%lld\n", sum);
}
return 0;
}
会爆int。。
UVA - 11136 Hoax or what
最新推荐文章于 2019-04-27 20:18:50 发布
本文探讨了程序设计和算法优化的关键技巧,包括排序算法、动态规划、哈希算法等核心概念,旨在提升代码效率与解决复杂问题的能力。
571

被折叠的 条评论
为什么被折叠?



