Orig Description
Score : 1300 points
Problem StatementA museum exhibits N jewels, Jewel 1, 2, ..., N.
The coordinates of Jewel i are (x_i, y_i) (the museum can be regarded as a two-dimensional plane), and the value of that jewel is v_i.
Snuke the thief will steal some of these jewels.
There are M conditions, Condition 1, 2, ..., M, that must be met when stealing jewels, or he will be caught by the detective.
Each condition has one of the following four forms:
(t_i =L, a_i, b_i) : Snuke can only steal at most b_i jewels whose x coordinates are a_i or smaller.
(t_i =R, a_i, b_i) : Snuke can only steal at most b_i jewels whose x coordinates are a_i or larger.
(t_i =D, a_i, b_i) : Snuke can only steal at most b_i jewels whose y coordinates are a_i or smaller.
(t_i =U, a_i, b_i) : Snuke can only steal at most b_i jewels whose y coordinates are a_i or larger.
Find the maximum sum of values of jewels that Snuke the thief can steal.
Constraints
1 \leq N \leq 80
1 \leq x_i, y_i \leq 100
1 \leq v_i \leq 10^{15}
1 \leq M \leq 320
t_i is L, R, U or D.
1 \leq a_i \leq 100
0 \leq b_i \leq N - 1
(x_i, y_i) are pairwise distinct.
(t_i, a_i) are pairwise distinct.
(t_i, b_i) are pairwise distinct.
InputInput is given from Standard Input in the following format:
N
x_1 y_1 v_1
x_2 y_2 v_2
:
x_N y_N v_N
M
t_1 a_1 b_1
t_2 a_2 b_2
:
t_M a_M b_M
OutputPrint the maximum sum of values of jewels that Snuke the thief can steal.
Sample Input 17
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
Sample Output 136
Stealing Jewel 1, 5, 6 and 7 results in the total value of 36.
Sample Input 23
1 2 3
4 5 6
7 8 9
1
L 100 0
Sample Output 20
Sample Input 34
1 1 10
1 2 11
2 1 12
2 2 13
3
L 8 3
L 9 2
L 10 1
Sample Output 313
Sample Input 410
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
Sample Output 4305223377000
Extracted Specification
An integer N (1 ≤ N ≤ 80), representing some quantity or size.
N tuples, each containing three integers (x, y, v), where 1 ≤ x, y ≤ 100 and 1 ≤ v ≤ 10^15.
An integer M (1 ≤ M ≤ 320), representing some quantity or size.
M tuples, each containing a character t from the set {'L', 'R', 'D', 'U'}, and two integers a (1 ≤ a ≤ 100) and b (0 ≤ b ≤ N - 1).
### Example Input:
```
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
```
### Function Signature:
Write a function f(N, coordinates, M, conditions) that takes in the input.
def f(N: int, coordinates: List[Tuple[int, int, int]], M: int, conditions: List[Tuple[str, int, int]]):
'''
N: an integer
coordinates: a list of tuples, each containing three integers
M: an integer
conditions: a list of tuples, each containing a character and two integers
'''
Test Case Generator
Here's a test case generator for the given problem statement about Snuke the thief and the jewels:
```python
import random
def tcgen():
# Generate number of jewels N (1 <= N <= 80)
N = random.randint(1, 80)
# Generate coordinates and values for each jewel
jewels = []
coordinates = set()
for _ in range(N):
while True:
x = random.randint(1, 100)
y = random.randint(1, 100)
if (x, y) not in coordinates:
coordinates.add((x, y))
break
v = random.randint(1, 10**15)
jewels.append((x, y, v))
# Generate number of conditions M (1 <= M <= 320)
M = random.randint(1, 320)
# Generate conditions
conditions = []
conditions_set = set()
for _ in range(M):
t = random.choice(['L', 'R', 'D', 'U'])
while True:
a = random.randint(1, 100)
b = random.randint(0, N - 1)
if (t, a) not in conditions_set and (t, b) not in conditions_set:
conditions_set.add((t, a))
conditions_set.add((t, b))
break
conditions.append((t, a, b))
return N, jewels, M, conditions
# Function to print the test case in the required format
def print_test_case():
N, jewels, M, conditions = tcgen()
print(N)
for x, y, v in jewels:
print(f"{x} {y} {v}")
print(M)
for t, a, b in conditions:
print(f"{t} {a} {b}")
# Example usage
print_test_case()
```
### Explanation:
- **N**: Randomly generate the number of jewels within the given range.
- **Jewels**: For each jewel, randomly generate distinct coordinates (x, y) and a value v within the constraints.
- **M**: Randomly generate the number of conditions within the given range.
- **Conditions**: Generate conditions ensuring that (t, a) and (t, b) pairs are unique as per the constraints.
You can run the `print_test_case()` function to generate a random test case and print it in the required format. Each time you run it, it will produce a different test case within the problem's constraints.
Extract Arguments
def extract_arguments(fh):
N = int(fh.readline().strip())
jewels = []
for _ in range(N):
x, y, v = map(int, fh.readline().strip().split())
jewels.append((x, y, v))
M = int(fh.readline().strip())
conditions = []
for _ in range(M):
t, a, b = fh.readline().strip().split()
a = int(a)
b = int(b)
conditions.append((t, a, b))
return N, jewels, M, conditions
# Example usage:
# if __name__ == "__main__":
# input_path = sys.argv[1]
# with open(input_path, 'r') as fh:
# N, jewels, M, conditions = extract_arguments(fh)
# print(N, jewels, M, conditions)