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.
A list of N tuples, each containing three integers, where the first two integers are between 1 and 100, and the third integer is between 1 and 10^15.
An integer M (1 ≤ M ≤ 320), representing some quantity or size.
A list of M tuples, each containing a character from the set {'L', 'R', 'U', 'D'}, and two integers, where the first integer is between 1 and 100, and the second integer is between 0 and 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, jewels, M, conditions) that takes in the input.
def f(N: int, jewels: List[Tuple[int, int, int]], M: int, conditions: List[Tuple[str, int, int]]):
'''
N: an integer
jewels: 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
Sure! Here's a test case generator for the given problem statement:
```python
import random
def tcgen():
# Generate the number of jewels (N)
N = random.randint(1, 80)
# Generate the coordinates and value of each jewel
jewels = []
for _ in range(N):
x = random.randint(1, 100)
y = random.randint(1, 100)
v = random.randint(1, 10**15)
jewels.append((x, y, v))
# Generate the number of conditions (M)
M = random.randint(1, 320)
# Generate conditions
conditions = []
types = ['L', 'R', 'D', 'U']
a_b_pairs = set()
for _ in range(M):
t = random.choice(types)
a = random.randint(1, 100)
b = random.randint(0, N - 1)
# Ensure (t, a, b) are pairwise distinct
while (t, a, b) in a_b_pairs:
t = random.choice(types)
a = random.randint(1, 100)
b = random.randint(0, N - 1)
a_b_pairs.add((t, a, b))
conditions.append((t, a, b))
# Format output
output = f"{N}\n"
for x, y, v in jewels:
output += f"{x} {y} {v}\n"
output += f"{M}\n"
for t, a, b in conditions:
output += f"{t} {a} {b}\n"
return output
# Example of generating a test case
print(tcgen())
```
This code generates test cases based on the problem constraints. It ensures that the coordinates and values of jewels are generated within the specified ranges and that the conditions are pairwise distinct as required by the problem. The `print(tcgen())` line at the end can be used to see an example of the generated test case.
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
# if __name__ == "__main__":
# input_path = sys.argv[1]
# with open(input_path, 'r') as fh:
# N, jewels, M, conditions = extract_arguments(fh)
# f(N, jewels, M, conditions)