Orig Description
Score : 200 points
Problem Statement
You are visiting a large electronics store to buy a refrigerator and a microwave.
The store sells A kinds of refrigerators and B kinds of microwaves. The i-th refrigerator ( 1 \le i \le A ) is sold at a_i yen (the currency of Japan), and the j-th microwave ( 1 \le j \le B ) is sold at b_j yen.
You have M discount tickets. With the i-th ticket ( 1 \le i \le M ), you can get a discount of c_i yen from the total price when buying the x_i-th refrigerator and the y_i-th microwave together. Only one ticket can be used at a time.
You are planning to buy one refrigerator and one microwave. Find the minimum amount of money required.
Constraints
All values in input are integers.
1 \le A \le 10^5
1 \le B \le 10^5
1 \le M \le 10^5
1 \le a_i , b_i , c_i \le 10^5
1 \le x_i \le A
1 \le y_i \le B
c_i \le a_{x_i} + b_{y_i}
Input
Input is given from Standard Input in the following format:
A B M
a_1 a_2 ... a_A
b_1 b_2 ... b_B
x_1 y_1 c_1
\vdots
x_M y_M c_M
Output
Print the answer.
Sample Input 12 3 1
3 3
3 3 3
1 2 1
Sample Output 15
With the ticket, you can get the 1-st refrigerator and the 2-nd microwave for 3+3-1=5 yen.
Sample Input 21 1 2
10
10
1 1 5
1 1 10
Sample Output 210
Note that you cannot use more than one ticket at a time.
Sample Input 32 2 1
3 5
3 5
2 2 2
Sample Output 36
You can get the 1-st refrigerator and the 1-st microwave for 6 yen, which is the minimum amount to pay in this case.
Note that using a ticket is optional.
Extracted Specification
An integer A (1 ≤ A ≤ 10^5), representing some quantity or size.
An integer B (1 ≤ B ≤ 10^5), representing some quantity or size.
An integer M (1 ≤ M ≤ 10^5), representing some quantity or size.
A list of integers of size A, where each integer is between 1 and 1e5.
A list of integers of size B, where each integer is between 1 and 1e5.
A list of M tuples, each containing three integers: an integer between 1 and A, an integer between 1 and B, and an integer between 1 and 1e5.
### Example Input:
```
3 1 1
3 3 3
3
1 2 1
```
### Function Signature:
Write a function f(A, B, M, listA, listB, listM) that takes in the input.
def f(A: int, B: int, M: int, listA: List[int], listB: List[int], listM: List[Tuple[int, int, int]]):
'''
A: an integer
B: an integer
M: an integer
listA: a list of integers
listB: a list of integers
listM: a list of tuples, each containing three integers
'''
Test Case Generator
Certainly! Below is a test case generator for the given problem statement:
```python
import random
def tcgen():
# Generate random values for A, B, M within the given constraints
A = random.randint(1, 10**5)
B = random.randint(1, 10**5)
M = random.randint(1, 10**5)
# Generate A kinds of refrigerators with prices between 1 and 100,000
a = [random.randint(1, 10**5) for _ in range(A)]
# Generate B kinds of microwaves with prices between 1 and 100,000
b = [random.randint(1, 10**5) for _ in range(B)]
# Generate M discount tickets
x, y, c = [], [], []
for _ in range(M):
x_i = random.randint(1, A)
y_i = random.randint(1, B)
# Ensure that c_i <= a[x_i-1] + b[y_i-1]
c_i = random.randint(1, a[x_i-1] + b[y_i-1])
x.append(x_i)
y.append(y_i)
c.append(c_i)
return A, B, M, a, b, x, y, c
# Example usage:
A, B, M, a, b, x, y, c = tcgen()
print(A, B, M)
print(' '.join(map(str, a)))
print(' '.join(map(str, b)))
for i in range(M):
print(x[i], y[i], c[i])
```
### Explanation
1. **A, B, M generation:**
- We generate random integers for `A`, `B`, and `M` within their respective ranges.
2. **Refrigerator prices (`a`):**
- We generate a list of `A` integers where each integer is between 1 and 100,000.
3. **Microwave prices (`b`):**
- We generate a list of `B` integers where each integer is between 1 and 100,000.
4. **Discount tickets (`x`, `y`, `c`):**
- For each discount ticket, generate `x_i` and `y_i` such that they refer to valid indices in the `a` and `b` lists.
- Generate a discount value `c_i` ensuring that it does not exceed the sum of the corresponding prices of the selected refrigerator and microwave.
This generator will create varying test cases within the constraints specified in the problem statement. Adjustments can be made to control the size and nature of the generated cases if specific types of test cases are required.
Extract Arguments
def extract_arguments(fh):
# Read the first line and parse A, B, M
A, B, M = map(int, fh.readline().strip().split())
# Read the next A lines for refrigerator prices
a = list(map(int, fh.readline().strip().split()))
# Read the next B lines for microwave prices
b = list(map(int, fh.readline().strip().split()))
# Initialize the discount tickets as an empty list
discounts = []
# Read the next M lines for discount tickets
for _ in range(M):
x, y, c = map(int, fh.readline().strip().split())
discounts.append((x, y, c))
return A, B, M, a, b, discounts
# if __name__ == "__main__":
# input_path = sys.argv[1]
# with open(input_path, 'r') as fh:
# A, B, M, a, b, discounts = extract_arguments(fh)
# f(A, B, M, a, b, discounts)