-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathS101.cpp
43 lines (43 loc) · 862 Bytes
/
S101.cpp
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
#include <cstdio>
int d[3001], p[3001];
int a[60001], b[60001];
int main() {
for (int i = 0; i <= 60000; i++) {
a[i] = b[i] = -1;
}
int n, m, x, y;
char c;
scanf("%d %d", &n, &m);
for (int i = 0; i < n; i++) {
scanf("%d %d %c", &x, &y, &c);
d[i] = x;
p[i] = y;
if (c == 'A') {
a[x] = i;
} else {
b[x] = i;
}
}
d[3000] = 99999;
p[3000] = 0;
a[60000] = 3000;
b[60000] = 3000;
for (int i = 60000; i >= 0; i--) {
if (a[i] == -1)
a[i] = a[i + 1];
if (b[i] == -1)
b[i] = b[i + 1];
}
int sum = 0;
for (int i = 0; i < m; i++) {
scanf("%d %d", &x, &y);
if (x < 0) x = -x;
if (y < 0) y = -y;
n = x > y ? x : y;
if (d[a[n]] != n && d[b[x + y]] != x + y) {
sum += d[a[n]] < d[b[x + y]] ? p[a[n]] : p[b[x + y]];
}
}
printf("%d\n", sum);
return 0;
}