-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathS101.pas
53 lines (53 loc) · 962 Bytes
/
S101.pas
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
49
50
51
52
53
var
d, p: array[1..3001] of longint;
a, b: array[0..60000] of longint;
i, n, m, x, y, sum: longint;
dummy, c: char;
begin
for i := 0 to 60000 do
begin
a[i] := -1;
b[i] := -1
end;
read(n, m);
for i := 1 to n do
begin
read(x, y, dummy, c);
d[i] := x;
p[i] := y;
if (c = 'A') then
a[x] := i
else
b[x] := i
end;
d[3001] := 99999;
p[3001] := 0;
a[60000] := 3001;
b[60000] := 3001;
for i := 59999 downto 0 do
begin
if (a[i] = -1) then
a[i] := a[i + 1];
if (b[i] = -1) then
b[i] := b[i + 1]
end;
sum := 0;
for i := 1 to m do
begin
read(x, y);
if (x < 0) then
x := -x;
if (y < 0) then
y := -y;
if (x > y) then
n := x
else
n := y;
if ((d[a[n]] <> n) and (d[b[x + y]] <> x + y)) then
if (d[a[n]] < d[b[x + y]]) then
sum := sum + p[a[n]]
else
sum := sum + p[b[x + y]]
end;
writeln(sum)
end.