atcoder#AGC031E. [AGC031E] Snuke the Phantom Thief
[AGC031E] Snuke the Phantom Thief
Score : points
Problem Statement
A museum exhibits jewels, Jewel . The coordinates of Jewel are (the museum can be regarded as a two-dimensional plane), and the value of that jewel is .
Snuke the thief will steal some of these jewels.
There are conditions, Condition , that must be met when stealing jewels, or he will be caught by the detective. Each condition has one of the following four forms:
- ( =
L
, , ) : Snuke can only steal at most jewels whose coordinates are or smaller. - ( =
R
, , ) : Snuke can only steal at most jewels whose coordinates are or larger. - ( =
D
, , ) : Snuke can only steal at most jewels whose coordinates are or smaller. - ( =
U
, , ) : Snuke can only steal at most jewels whose coordinates are or larger.
Find the maximum sum of values of jewels that Snuke the thief can steal.
Constraints
- is
L
,R
,U
orD
. - are pairwise distinct.
- are pairwise distinct.
- are pairwise distinct.
Input
Input is given from Standard Input in the following format:
Output
Print the maximum sum of values of jewels that Snuke the thief can steal.
7
1 3 6
1 5 9
3 1 8
4 3 8
6 2 9
5 4 11
5 7 10
4
L 3 1
R 2 3
D 5 3
U 4 2
36
Stealing Jewel and results in the total value of .
3
1 2 3
4 5 6
7 8 9
1
L 100 0
0
4
1 1 10
1 2 11
2 1 12
2 2 13
3
L 8 3
L 9 2
L 10 1
13
10
66 47 71040136000
65 77 74799603000
80 53 91192869000
24 34 24931901000
91 78 49867703000
68 71 46108236000
46 73 74799603000
56 63 93122668000
32 51 71030136000
51 26 70912345000
21
L 51 1
L 7 0
U 47 4
R 92 0
R 91 1
D 53 2
R 65 3
D 13 0
U 63 3
L 68 3
D 47 1
L 91 5
R 32 4
L 66 2
L 80 4
D 77 4
U 73 1
D 78 5
U 26 5
R 80 2
R 24 5
305223377000