Problem p02748 - Generation 1

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.
An integer B (1 ≤ B ≤ 10^5), representing some quantity.
An integer M (1 ≤ M ≤ 10^5), representing some quantity.
A list of integers of size A, where each integer is between 1 and 10^5.
A list of integers of size B, where each integer is between 1 and 10^5.
M tuples, each containing three integers. The first integer is in the range [1, A], the second integer is in the range [1, B], and the third integer is between 1 and 10^5.

### Example Input:

```
3 3 1
3 3 3
3 3 3
1 2 1
```

### Function Signature:
Write a function f(A, B, M, list_A, list_B, discounts) that takes in the input.
```python
def f(A: int, B: int, M: int, list_A: List[int], list_B: List[int], discounts: List[Tuple[int, int, int]]):
    '''
    A: an integer
    B: an integer
    M: an integer
    list_A: a list of integers
    list_B: a list of integers
    discounts: a list of tuples, each containing three integers
    '''
```

Test Case Generator

Sure! Here's a test case generator for the given problem statement about buying a refrigerator and a microwave.

```python
import random

def generate_test_case():
    # Constraints
    A = random.randint(1, 10**5)
    B = random.randint(1, 10**5)
    M = random.randint(1, 10**5)
    
    # Generate A kinds of refrigerators prices
    a = [random.randint(1, 10**5) for _ in range(A)]
    
    # Generate B kinds of microwaves prices
    b = [random.randint(1, 10**5) for _ in range(B)]
    
    # Generate M discount tickets
    tickets = []
    for _ in range(M):
        x_i = random.randint(1, A)
        y_i = random.randint(1, B)
        c_i = random.randint(1, a[x_i-1] + b[y_i-1])
        tickets.append((x_i, y_i, c_i))
    
    return A, B, M, a, b, tickets

# Function to print the test case in the required format
def print_test_case():
    A, B, M, a, b, tickets = generate_test_case()
    
    print(A, B, M)
    print(" ".join(map(str, a)))
    print(" ".join(map(str, b)))
    for ticket in tickets:
        print(ticket[0], ticket[1], ticket[2])

# Example usage
print_test_case()
```

Explanation:

1. **generate_test_case() Function**:
    - Generates random values for \(A\), \(B\), and \(M\) within their respective constraints.
    - Creates lists of random integers for the prices of \(A\) refrigerators and \(B\) microwaves.
    - Generates \(M\) discount tickets, where each ticket specifies two indices and a discount amount. The discount amount is ensured to be within the valid range by using the constraint \(c_i \le a_{x_i} + b_{y_i}\).

2. **print_test_case() Function**:
    - Calls the `generate_test_case()` function to generate a test case.
    - Prints the test case in the required input format.

This code will produce a random test case that adheres to the given problem constraints.

Extract Arguments

def extract_arguments(fh):
    A, B, M = map(int, fh.readline().strip().split())
    a = list(map(int, fh.readline().strip().split()))
    b = list(map(int, fh.readline().strip().split()))
    discounts = []
    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