codeforces 228 div.2

本文从WordPress迁移而来, 查看全部WordPress迁移文章

E.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <queue>
#include <algorithm>
using namespace std;
#define LL long long
#define PII pair<int,int>
#define CL(xx,yy) memset((xx),(yy),sizeof((xx)))
#define PB push_back
#define MP make_pair
#define N 110

int n;
vector<int>num;

int main (){
while(scanf("%d",&n)!=EOF){
num.clear();
int sum[2] = {0,0};
for(int i = 0; i < n; i++){
int m,x;
scanf("%d",&m);
int mid = m/2;
for(int i = 0; i < mid; i++){
scanf("%d",&x);
sum[0] += x;
}
if(m&1){
scanf("%d",&x);
num.push_back(x);
}
for(int i = 0 ; i < mid; i++){
scanf("%d",&x);
sum[1] += x;
}
}
sort(num.begin(),num.end());
reverse(num.begin(),num.end());
for(int i = 0; i < num.size(); i++){
sum[i%2] += num[i];
}
printf("%d %d\n",sum[0],sum[1]);
}
return 0;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
n = int(raw_input())
ans = [0,0]
num = []
for i in range(n):
a = map(int,raw_input().split())
mid = a[0] / 2;
st = mid+1
if a[0] % 2 == 1:
num.append(a[mid+1])
st += 1
ans[0] += sum(a[1:mid+1])
ans[1] += sum(a[st:a[0]+1])
num.sort()
num.reverse()
for i in range(len(num)):
ans[i%2] += num[i]
print ans[0] , ans[1]