forked from gitter-badger/Interview
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCF558A.cpp
More file actions
46 lines (43 loc) · 893 Bytes
/
CF558A.cpp
File metadata and controls
46 lines (43 loc) · 893 Bytes
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
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
using namespace std;
struct Tree {
int x, num;
bool friend operator<(Tree a, Tree b) {
return a.x < b.x;
}
};
Tree t[1111];
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d %d", &t[i].x, &t[i].num);
}
sort(t, t + n);
int l = 0, r = 0;
for (int i = 0; i < n; i++) {
if (t[i].x < 0) {
l += 1;
} else {
r += 1;
}
}
int ans = 0;
if (l < r) {
for (int i = 0; i < l * 2 + 1; i++) {
ans += t[i].num;
}
} else if (l == r) {
for (int i = 0; i < n; i++) {
ans += t[i].num;
}
} else {
for (int i = n - 1; i > n - 1 - r * 2 - 1; i--) {
ans += t[i].num;
}
}
printf("%d\n", ans);
}