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 lines follow, each containing three integers X, Y, and V where:
- 1 ≤ X, Y ≤ 100
- 1 ≤ V ≤ 10^15
An integer M (1 ≤ M ≤ 320), representing some quantity or size.
M lines follow, each containing a character T from the set {'L', 'R', 'U', 'D'}, and two integers A and B where:
- 1 ≤ A ≤ 100
- 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_values, M, conditions) that takes in the input.
def f(N: int, coordinates_values: List[Tuple[int, int, int]], M: int, conditions: List[Tuple[str, int, int]]):
'''
N: an integer
coordinates_values: 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
To create a test case generator for the given problem, we need to ensure that the generated test cases adhere to the constraints and formats as stated in the problem. Here's how we can implement such a generator:
```python
import random
def generate_jewel_coordinates_and_values(N):
coordinates = set()
jewels = []
while len(jewels) < N:
x = random.randint(1, 100)
y = random.randint(1, 100)
if (x, y) not in coordinates:
coordinates.add((x, y))
v = random.randint(1, 10**15)
jewels.append((x, y, v))
return jewels
def generate_conditions(M, N):
conditions = set()
condition_types = ['L', 'R', 'U', 'D']
while len(conditions) < M:
t = random.choice(condition_types)
a = random.randint(1, 100)
b = random.randint(0, N - 1)
condition = (t, a, b)
if condition not in conditions:
conditions.add(condition)
return list(conditions)
def tcgen():
N = random.randint(1, 80)
jewels = generate_jewel_coordinates_and_values(N)
M = random.randint(1, 320)
conditions = generate_conditions(M, N)
return N, jewels, M, conditions
def format_test_case(N, jewels, M, conditions):
test_case = []
test_case.append(str(N))
for x, y, v in jewels:
test_case.append(f"{x} {y} {v}")
test_case.append(str(M))
for t, a, b in conditions:
test_case.append(f"{t} {a} {b}")
return "\n".join(test_case)
# Example of generating a test case
N, jewels, M, conditions = tcgen()
formatted_test_case = format_test_case(N, jewels, M, conditions)
print(formatted_test_case)
```
**Explanation:**
1. **`generate_jewel_coordinates_and_values(N)`:** This function generates `N` unique jewel coordinates `(x, y)` and assigns a random value `v` to each jewel. The coordinates are ensured to be unique by storing them in a set.
2. **`generate_conditions(M, N)`:** This function generates `M` unique conditions. Each condition is a tuple `(t, a, b)` where `t` is one of the four types (`L`, `R`, `U`, `D`), `a` is a random integer from 1 to 100, and `b` is a random integer from 0 to `N-1`. The uniqueness of conditions is ensured by storing them in a set.
3. **`tcgen()`:** This is the main function that generates the entire test case:
- It first generates a random `N` (number of jewels).
- It then generates the list of jewels and their properties.
- It generates a random `M` (number of conditions).
- It generates the list of conditions.
4. **`format_test_case(N, jewels, M, conditions)`:** This function formats the generated test case into the required input format for the problem.
By running the `tcgen()` function, we can generate a test case for the given problem and format it appropriately to be used as input for testing.
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