Problem:


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 1

2 3 1
3 3
3 3 3
1 2 1

Sample Output 1

5

With the ticket, you can get the 1-st refrigerator and the 2-nd microwave for 3+3-1=5 yen.

Sample Input 2

1 1 2
10
10
1 1 5
1 1 10

Sample Output 2

10

Note that you cannot use more than one ticket at a time.

Sample Input 3

2 2 1
3 5
3 5
2 2 2

Sample Output 3

6

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.



Sample input:
2 3 1
3 3
3 3 3
1 2 1


Sample output:
5

Submission status: Runtime Error

Solution code:
P = list(map(int,input().split()))
Q = list(map(int,input().split()))
S = P
T = Q
S.sort()
T.sort()
minimum = (S[0]+T[0])
K = 10**9
for i in range(M):
    x,y,c = map(int,input().split())
    S = P[x-1]+Q[y-1]-c
    if S=<K:
        if S <= 0:
            K = 0
        else:
            K = S
if minimum>K:
    print(K)
else:
    print(minimum)

Submission status: Runtime Error

Solution code:
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

s = []
s.append(min(a) + min(b))

for i in range(M):
    x_i, y_i, c_i = map(int, input().split())
    minus = a[x_i - 1] + a[y_i - 1] - c_i
    s.append(minus)

print(min(s))

Submission status: Runtime Error

Solution code:
def main():
    a, b, m = map(int, input().split())
    priceOfMicrowaves = list(map(int, input().split()))
    priceOfRefrigerators = list(map(int, input().split()))
    priceTable = [list(map(int,input().split())) for i in range(m)]
    cheepest = priceOfMicrowaves[0] + priceOfRefrigerators[0]
    for price in priceTable:
        if priceOfMicrowaves[price[0]-1] - price[2] >= cheepest:
            continue
        elif priceOfMicrowaves[price[1]-1] - price[2] >= cheepest:
            continue
        if priceOfMicrowaves[price[0]-1]+priceOfRefrigerators[price[1]-1]-price[2] < cheepest:
            cheepest = priceOfMicrowaves[price[0]-1]+priceOfRefrigerators[price[1]-1]-price[2]
    for p in priceOfMicrowaves:
        if p >= cheepest:
            continue
        for q in priceOfRefrigerators:
            if q >= cheepest:
                continue
            if p + q < cheepest:
                cheepest = p + q
    print(cheepest)
    
main()

Submission status: Runtime Error

Solution code:
a,b,m=map(int, input().split())
rei=list(map(int, input().split())) 
den=list(map(int, input().split())) 
cou = [0] * m
ans = []
for i in range(m):
	cou[i]=list(map(int, input().split()))
	ans.append(rei[cou[i][0]-1]+den[cou[i][1]-1]-cou[i][2])
for i in range(b):
	for j in range(a):
		ans.append(rei[j]+den[i]

Submission status: Runtime Error

Solution code:
A, B, M = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))

import numpy as np
a_np = np.array(a)[:, None]
b_np = np.array(b)[None, :]
a_b = a_np + b_np

C = np.zeros((A, B), dtype=np.int)
for i in range(M):
    x, y, c = list(map(int, input().split()))
    if c > C[x-1, y-1]:
        C[x-1, y-1] = c

print(np.min(a_b - C))

Submission status: Runtime Error

Solution code:
A,B,M=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
min_price=min(a)+min(b)
for i in range(M):
    m=list(map(int,input().split()))
    tmp_price=a[m[0]]+b[m[1]]-m[2]
    if min_price>tmp_price:
        min_price=tmp_price
print(min_price)

Submission status: Runtime Error

Solution code:
# coding: utf-8
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a1 = sorted(a)
b1 = sorted(b)
z = [list(map(int, input().split())) for _ in range(M)]

num1 = a1[0] + b1[0]
# print("num1:", num1)        
num1 = min(num1)
# print("num1:", num1)
for i in range(M):
    x, y, c = z[i]
    num = a[x - 1] + b[y - 1] - c
    if num < num1:
        num1 = num
print(num1)

Submission status: Runtime Error

Solution code:
def main():
    a, b, m = map(int, input().split())
    priceOfMicrowaves = list(map(int, input().split()))
    priceOfRefrigerators = list(map(int, input().split()))
    priceTable = [list(map(int,input().split())) for i in range(m)]
    cheepest = priceOfMicrowaves[0] + priceOfRefrigerators[0]
    for price in priceTable:
        if priceOfMicrowaves[price[0]-1] >= cheepest:
            continue
        elif priceOfMicrowaves[price[1]-1] >= cheepest:
            continue
        if priceOfMicrowaves[price[0]-1]+priceOfRefrigerators[price[1]-1]-price[2] < cheepest:
            cheepest = priceOfMicrowaves[price[0]-1]+priceOfRefrigerators[price[1]-1]-price[2]
    for p in priceOfMicrowaves:
        if p >= cheepest:
            continue
        for q in priceOfRefrigerators:
            if q >= cheepest:
                continue
            if p + q < cheepest:
                cheepest = p + q
    print(cheepest)
    
main()

Submission status: Runtime Error

Solution code:
a,b,m=map(int, input().split())
rei=list(map(int, input().split())) 
den=list(map(int, input().split())) 
cou = [0] * m[2]
ans = []
for i in range(m[2]):
	cou[i]=list(map(int, input().split()))
	ans.append(rei[cou[i][0]-1]+den[cou[i][1]-1]-cou[i][2])
for i in range(b):
	for j in range(len(a)):
		ans.append(rei[j]+den[i])
print(min(ans))

Submission status: Runtime Error

Solution code:
A, B, M = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
minimum = a[0]+b[0]

for k in range(M):
    x,y,c = map(int,input().split())
    tmp = a[x-1]+a[y-1]-c
    if minimum > tmp:
        minimum = tmp

a.sort()
b.sort()

tmpind = b[0]
for i in a:
    if i + tmpind > minimum:
        break
    for ind, j in enumerate(b):
        tmp = i + j
        if minimum > tmp:
            minimum = tmp
        else:
            tmpind = ind
            break

print(minimum)

Submission status: Runtime Error

Solution code:
A, B, M = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))

import numpy as np
a_np = np.array(a)[:, None]
b_np = np.array(b)[None, :]
a_b = a_np + b_np

C = np.zeros((A, B), dtype=np.int)
for i in range(M):
    x, y, c = list(map(int, input().split()))
    C[x-1, y-1] = np.max(c, C[x-1, y-1])

print(np.min(a_b - C))

Submission status: Runtime Error

Solution code:
A, B, M = map(int, input().split())
x, y, c = [0] * M, [0] * M, [0] * M
a = list(map(int, input().split()))
b = list(map(int, input().split()))
for i in range(M):
    x[i], y[i], c[i] = map(int, input().split())
ans = 0
sav = 0
maxc = max(c)
ci = c.index(maxc)
disc = a[ci - 1] + b[ci - 1] - maxc
print(min(disc, min(a) + min(b)))

Submission status: Runtime Error

Solution code:
a,b,m=map(int, input().split())
rei=list(map(int, input().split())) 
den=list(map(int, input().split())) 
cou = [0] * m[2]
ans = []
for i in range(m[2]):
	cou[i]=list(map(int, input().split()))
	ans.append(rei[cou[i][0]-1]+den[cou[i][1]-1]-cou[i][2])
for i in range(b):
	for j in range(len(a):
		ans.append(rei[j]+den[i])
print(min(ans))

Submission status: Runtime Error

Solution code:
a, b, m = list(map(int, input().split()))

pa = [int(p) for p in input().split()]
pb = [int(p) for p in input().split()]

pc = []

for c in range(m):
  x, y, d = list(map(int, input().split()))
  pc.append(pa[x-1]+pa[y-1]-d)
  
min_c = min(pc)
if min_c<0:
  min_c=0
min_ab = min(pa)+min(pb)

if min_c < min_ab:
  print(min_c)
else:
  print(min_ab)

Submission status: Runtime Error

Solution code:
A,B,M=map(int,input().split())
a=list(map(int,input().split())
b=list(map(int,input().split())
min_price=min(a)+min(b)
for i in range(M):
    m=list(map(int,input().split())
    tmp_price=a[m[0]]+b[m[1]]-m[2]
    if min_price>tmp_price:
        min_price=tmp_price
print(min_price)

Submission status: Runtime Error

Solution code:
data = input().split(" ")
A = input().split(" ")
B = input().split(" ")
total = 0
a = 0
b = 0

for i in data:
    i = int(i)
for i in A:
    i = int(i)
for i in B:
    i = int(i)

for i in range(data[2]):
    data1 = input().split()
    for i in data1:
        i = int(i)
    data2 = A[data1[0]] + B[data[1]] - data1[2]
    if total > data2:
        total = data2

for i in A:
    if a > i:
        a = i
for i in B:
    if b > i:
        b = i

if total > a+b:
    total = a+b

print(total)

Submission status: Runtime Error

Solution code:
a, b, m = map(int, input().split())
a1 = list(map(int, input().split()))
b1 = list(map(int, input().split()))

disc = [list(map(int, input().split())) for i in range(m)]

import itertools
import numpy as np

b2 = np.array(b1)
b2 = np.tile(b2, (a,1))

ans = []
from collections import deque
ans = deque(ans)

for i in range(a):
    ans.append( min( b2[i] + np.tile(a1[i], b) ) )


for i in range(m):
    ans.append( a1[disc[i][0]-1] + b1[disc[i][1]-1] - disc[i][2] )

ans = list(ans)
print(min(ans))

Submission status: Runtime Error

Solution code:
R = lambda: tuple(map(int, input().split()))
A, B, M = R()
a, b = R(), R()
l = (R() for _ in range(M))
print(min(a[x - 1] + b[x - 1] - c for x, y, c in l))

Submission status: Runtime Error

Solution code:
A,B,M = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
x = [0]*M
y = [0]*M
z = [0]*M
for i in range(M):
  x[i],y[i],z[i] = map(int,input().split())
zsort = sorted(z)
mi = zsort[-1]
ind = z.index(mi)
am = min(a)
bm = min(b)
mae = am + bm
indxy = a[ind-1] + b[ind-1] - mi


if mae < indxy:
  print(mae)
else:
  print(indxy)

Submission status: Runtime Error

Solution code:
a, b, m = input().split()
a, b, m = int(a), int(b), int(m)
a_values = input().split()
b_values = input().split()
m_values = {}
for i in range(m):
  m[i] = input().split()

min = int(a_values[m[0][0]]) + int(b_values[m[0][1]]) - int(m[0][2])
for i in range(1, m):
  now = int(a_values[m[i][0]]) + int(b_values[m[i][1]]) - int(m[i][2])
  if min > now:
    min = now
print(min)

Submission status: Runtime Error

Solution code:
import sys

def main():
    input = sys.stdin.readline

    a, b, m = input().split()
    a, b, m = int(a), int(b), int(m)
    alist = input().split()
    blist = input().split()

    waribiki = [input().split() for _ in range(m)]
    
    res = [200000] * 200001
    count = 0
    for i in range(a):
      for j in range(b):
        res[count] = int(alist[i]) + int(blist[j])
        count += 1

    for i in range(m):
        res[count] = int(alist[int(waribiki[i][0])-1]) + int(blist[int(waribiki[i][1])-1]) - int(waribiki[i][2])
        count += 1
      
    print(min(res))


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
a, b, m = map(int, input().split())
    priceOfMicrowaves = list(map(int, input().split()))
    priceOfRefrigerators = list(map(int, input().split()))
    priceTable = [list(map(int,input().split())) for i in range(m)]
    cheepest = priceOfMicrowaves[0] + priceOfRefrigerators[0]
    for p in priceOfMicrowaves:
        for q in priceOfRefrigerators:
            if p + q < cheepest:
                cheepest = p + q
    for price in priceTable:
        if priceOfMicrowaves[price[0]-1]+priceOfRefrigerators[price[1]-1]-price[2] < cheepest:
            cheepest = priceOfMicrowaves[price[0]-1]+priceOfRefrigerators[price[1]-1]-price[2]
    print(cheepest)

Submission status: Runtime Error

Solution code:
A, B, M = input().split()
A=int(A)
B=int(B)
M=int(M)
a = list(map(int, input().split()))
b = list(map(int, input().split()))
x = [list(map(int, input().split())) for i in range(M)]

dis = []
for i in range(M):
    m = x[i][0]
    n = x[i][0]
    dis.append(a[m] + b[n] - x[i][2])
    
a.sort()
b.sort()

dis.append(a[0]+b[0])

print(min(dis))

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
A, B, M = map(int,  input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
sum = [0.0] * (A * B)

for i in range(M):
        x, y, c = map(int,  input().split())
        sum[(y-1)*A + (x-1)] -= c

for ia in range(A):
        for ib in range(B):
                sum[ib*A + ia] += a[ia] + b[ib]

sum.sort()

i=0
while sum[i] < 0:
        i+=0
print(int(sum[i]))

Submission status: Runtime Error

Solution code:
import sys

def main():
    input = sys.stdin.readline

    _, _, m = input().split()
    m = int(m)
    alist = input().split()
    blist = input().split()

    waribiki = [input().split() for _ in range(m)]
    
    res = [200000] * 200001
    count = 0
    for a in alist:
      for b in blist:
        res[count] = int(a) + int(b)
        count += 1

    for i in range(m):
        res[count] = int(alist[int(waribiki[i][0])-1]) + int(blist[int(waribiki[i][1])-1]) - int(waribiki[i][2])
        count += 1
      
    print(min(res))


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
a, b, m = map(int, input().split())
a1 = list(map(int, input().split()))
b1 = list(map(int, input().split()))

disc = [list(map(int, input().split())) for i in range(m)]

import itertools
import numpy as np

b2 = np.array(b1)
b2 = np.tile(b2, (a,1))

for i in range(a):
    b2[i] = b2[i] + np.tile(a1[i], b)


ans = []
from collections import deque
ans = deque(ans)
for i in range(m):
    ans.append( a1[disc[i][0]-1] + b1[disc[i][1]-1] - disc[i][2] )

ans = list(ans)
print(min(np.min(b2), min(ans)))

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
A, B, M = map(int,  input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
sum = [0.0] * (A * B)

for i in range(M):
        x, y, c = map(int,  input().split())
        sum[(y-1)*A + (x-1)] -= c

for ia in range(A):
        for ib in range(B):
                sum[ib*A + ia] += a[ia] + b[ib]

sum.sort()

i=0
while sum[i] < 0:
        i+=0
print(sum[i])

Submission status: Runtime Error

Solution code:
a_s = sorted(enumerate(map(int, raw_input().split())), key=lambda t: t[1])
b_s = sorted(enumerate(map(int, raw_input().split())), key=lambda t: t[1])
w = [[0] * B] * A
max_w = 0
for _ in xrange(M):
    x, y, c = map(int, raw_input().split())
    w[x-1][y-1] = c
    max_w = max(max_w, c)

cost = 10 ** 20
for i, a in a_s:
    if a + b_s[0][1] - max_w > cost:
        break
    for j, b in b_s:
        cost = min(cost, a + b - w[i][j])
        if a + b - max_w > cost:
            break

print cost

Submission status: Runtime Error

Solution code:
A,B,M = map(int,input().split())
A_ = list(map(int,input().split()))
B_ = list(map(int,input().split()))
mini =min(A_) + min(B_)
for i in range(M):
    array = list(map(int,input().split()))
    m = A_[array[0]-1] + B_[array[0]-1] -array[2]
    if(mini > m):
        mini = m
print(mini)

Submission status: Runtime Error

Solution code:

#include<stdio.h>

void set_data(int data[], int n){
    for(int i = 0; i < n; i++){
        scanf("%d", &data[i]);
    }
}

void set_data2(int data[][3], int n){
    for(int i = 0; i < n; i++){
        for(int j = 0; j < 3; j++){
            scanf("%d", &data[i][j]);
        }
    }
}

int min(int data[], int n){
    int min = data[0];
    for(int i = 0; i < n; i++){
        if(min > data[i]){
            min = data[i];
        }
    }
    return min;
}

int main(void){
    int a, b, m;
    scanf("%d""%d""%d", &a, &b, &m);
    int data_a[a], data_b[b], data[m][3];
    set_data(data_a, a);
    set_data(data_b, b);
    set_data2(data, m);

    int min1 = data_a[data[0][0] - 1] + data_b[data[0][1] - 1] - data[0][2];
    int min2 = min(data_a, a) + min(data_b, b), ans;
    for(int i = 0; i < m; i++){
        if(min1> data_a[data[i][0] - 1] + data_b[data[i][1] - 1] - data[i][2]){
            min1 = data_a[data[i][0] - 1] + data_b[data[i][1] - 1] - data[i][2];
        }
    }
    if(min1 > min2){
        ans = min2;
    }else{
        ans = min1;
    }
    printf("%d\n", ans);
    return 0;
}

Submission status: Runtime Error

Solution code:
import sys

def main():
    input = sys.stdin.readline

    _, _, m = input().split()
    m = int(m)
    alist = input().split()
    blist = input().split()

    waribiki = [input().split() for _ in range(m)]
    
    res = [200000] * 200000
    count = 0
    for a in alist:
      for b in blist:
        res[count] = int(a) + int(b)
        count += 1

    # for i in range(m):
    #     res[count] = int(alist[int(waribiki[i][0])-1]) + int(blist[int(waribiki[i][1])-1]) - int(waribiki[i][2])
    #     count += 1
      
    print(min(res))


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

s = []
for a_i in a:
    for b_i in b:
        sum_ab = a_i + b_i
        s.append(sum_ab)

for i in range(M):
    x_i, y_i, c_i = map(int, input().split())
    minus = a[x_i - 1] + a[y_i - 1] - c_i
    s.append(minus)

print(min(s))

Submission status: Runtime Error

Solution code:
line = [int(i) for i in input().split(' ')]
set_line = set(line)
A = [int(i) for i in input().split(' ')]
B = [int(i) for i in input().split(' ')]
C = []
for i in range(line[2]):
  C.append([int(i) for i in input().split(' ')])
  
if line.count(1) == 3:
  print(A[0] + B[0] - C[2])
else:
  min_price = min(A) + min(B)
  for i in range(len(C)):
    price = A[C[i][0]] + B[C[i][1]] - C[i][2]
    if min_price > price:
      min_price = price
  print(min_price)

Submission status: Runtime Error

Solution code:
import sys

def main():
    input = sys.stdin.readline

    _, _, m = input().split()
    m = int(m)
    alist = input().split()
    blist = input().split()

    waribiki = [input().split() for _ in range(m)]
    
    res = [200000] * 200000
    count = 0
    for a in alist:
      for b in blist:
        res[count] = int(a) + int(b)
        count += 1

    for i in range(m):
        res[count] = int(alist[int(waribiki[i][0])-1]) + int(blist[int(waribiki[i][1])-1]) - int(waribiki[i][2])
        count += 1
      
    print(min(res))


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import sys

def main():
    input = sys.stdin.readline

    _, _, m = input().split()
    m = int(m)
    alist = input().split()
    blist = input().split()

    waribiki = [input().split() for _ in range(m)]
    
    res = [200000] * (len(alist)*len(blist) + m)
    count = 0
    for a in alist:
      for b in blist:
        res[count] = int(a) + int(b)
        count += 1

    for i in range(m):
        res[count] = int(alist[int(waribiki[i][0])-1]) + int(blist[int(waribiki[i][1])-1]) - int(waribiki[i][2])
        count += 1
      
    print(min(res))


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
aa, bb, m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

couponMin = float("INF")
for i in range(m):
    x, y, c = map(int, input().split())
    cc = a[x - 1] + b[x - 1] - c
    couponMin = min(couponMin, cc)

print(min(min(a) + min(b), couponMin))

Submission status: Runtime Error

Solution code:
A,B,M = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
x = [0] * M
y = [0] * M
c = [0] * M
for i in range(M):
    x[i], y[i], c[i] = map(int, input().split())


ans= 0
tmp =0
#割引券を使わない場合
ans = min(a) + min(b)

#割引券を使う場合
for i in range(M):
    if a[x[i]-1] + b[y[i]-1] - c[i] < ans:
        ans = a[x[i]] + b[y[i]] - c[i]

print(ans)

Submission status: Runtime Error

Solution code:
import sys

def main():
    input = sys.stdin.readline

    _, _, m = input().split()
    m = int(m)
    alist = input().split()
    blist = input().split()

    waribiki = [input().split() for _ in range(m)]
    
    res = [20000] * (len(alist)*len(blist) + m)
    count = 0
    for a in alist:
      for b in blist:
        res[count] = int(a) + int(b)
        count += 1

    for i in range(m):
        try:
            res[count] = int(alist[int(waribiki[i][0])-1]) + int(blist[int(waribiki[i][1])-1]) - int(waribiki[i][2])
        except Exception:
            res[count] = 20000
        count += 1
      
    print(min(res))


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
A, B, M = map(int,  input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
sum = [0] * (A * B)

for i in range(M):
        x, y, c = map(int,  input().split())
        sum[(y-1)*A + (x-1)] = -c

for ia in range(A):
        for ib in range(B):
                sum[ib*A + ia] += a[ia] + b[ib]

sum.sort()

i=0
while sum[i] < 0:
        i+=0
print(sum[i])

Submission status: Runtime Error

Solution code:
A, B, M = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))

import numpy as np
a_np = np.array(a)[:, None]
b_np = np.array(b)[None, :]
a_b = a_np + b_np

C = np.zeros((A, B), dtype=np.int)
for i in range(M):
    x, y, c = list(map(int, input().split()))
    C[x-1, y-1] = np.max([c, C[x-1, y-1]])

print(np.min(a_b - C))

Submission status: Runtime Error

Solution code:
a, b, m = map(int, input().split())
priceOfMicrowaves = map(int, input().split())
priceOfRefrigerators = map(int, input().split())
priceTable = [list(map(int,input().split())) for i in range(m)]

cheepest = priceOfMicrowaves[0] + priceOfRefrigerators[0]
for p in priceOfMicrowaves:
    for q in priceOfRefrigerators:
        if p + q < cheepest:
            cheepest = p + q
    
for price in priceTable:
    if priceOfMicrowaves[price[0]-1]+priceOfRefrigerators[price[1]-1]-price[2] < cheepest:
        cheepest = priceOfMicrowaves[price[0]-1]+priceOfRefrigerators[price[1]-1]-price[2]
        
print(cheepest)

Submission status: Runtime Error

Solution code:
A , B , M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
M -= 1
ans = []
for i in range():
    q = list(map(int, input().split()))
    x = a[q[0]-1] + b[q[1]-1] - q[2]
    ans.append(x)
print(min(ans))

Submission status: Runtime Error

Solution code:
A, B, m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ab = []
for i in range(min(A,B)):
  ab.append([a[i], b[i]])
ab.sort()

ans = 10**5+1
for i in range(m):
  x, y, c = map(int, input().split())
  if i <= min(A, B):
    ans = min(ans, a[x-1] + b[y-1] - c, ab[i][0] + ab[i][1])
  else: 
    ans = min(ans, a[x-1] + b[y-1] - c)
  
print(ans)

Submission status: Runtime Error

Solution code:
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
# 2次元配列
grid = []
for i in range(M):
    array = list(map(int, input().strip().split()))
    grid.append(array)
    
sum_fee = []
comb_pro = list(itertools.product(a, b))
for com in comb_pro:
    sum_fee.append(sum(com))

for l, m , n in grid:
    sum_fee.append(a[l-1] + b[m-1] - n)
    
print(min(sum_fee))

Submission status: Runtime Error

Solution code:
# coding: utf-8
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
z = [list(map(int, input().split())) for _ in range(M)]

num1 = [a[i] + b[i] for i in range(max(A, B))]

for i in range(M):
    x, y, c = z[i]
    num = a[x - 1] + b[y - 1] - c
    num1.append(num)
# print(num1)
print(min(num1))

Submission status: Runtime Error

Solution code:
zyouken = [int(i) for i in input().split()]
reizouko = [int(a) for a in input().split()]
densirenzi = [int(b) for b in input().split()]
minkouho = min(reizouko) + min(densirenzi)
while zyouken[2] > 0:
    zyouken[2] = zyouken[2] - 1
    waribiki = [int(w) for w in input().split()]
    mink = reizouko[waribiki[0]] + densirenzi[waribiki[1]] - waribiki[2]
    if mink < minkouho:
        minkouho = mink
print(minkouho)

Submission status: Runtime Error

Solution code:
A,B,M=map(int,input().split())
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]

c={}
for _ in range(M)
    xi,yi,ci=input().split()
    c[xi.zfill(6)+yi.zfill(6)]=int(ci)

ans_list=[]

for i in range(A):
    for j in range(B):
        ans=a[i]+b[i]
        if str(i+1).zfill(6)+str(j+1).zfill(6) in c.key:
            ans-=c[str(i+1).zfill(6)+str(j+1).zfill(6)]
        ans_list.append(ans)

print(min(ans_list))

Submission status: Runtime Error

Solution code:
A , B , M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = []
for i in range(M-2):
    q = list(map(int, input().split()))
    x = a[q[0]-1] + b[q[1]-1] - q[2]
    ans.append(x)
print(min(ans))

Submission status: Runtime Error

Solution code:
aa, bb, m = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
x = []
y = []
c = []
for i in range(m):
  x1, y1, c1 = list(map(int,input().split()))
  x.append(x1)
  y.append(y1)
  c.append(c1)

price = []
  
for i in range(m):
  price.append(a[x[i] - 1] + b[y[i] - 1] - c[i])
  
  
  
print(min(price, min(a) + min(b)))

Submission status: Runtime Error

Solution code:
A, B, M = map(int, input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
X = [input() for i in range(M)]

min_price = min(a) + min(b)

for i in X:
    min_price = min(min_price, a[int(i[0])-1] + b[int(i[2])-1] - int(i[4:]))

print(min_price)

Submission status: Runtime Error

Solution code:
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
value = min(a) + min(b)
for i in range(M):
    x,y,c = list(map(int, input().split()))
    if A[x-1] + B[y-1] - c < value:
        value = A[x-1] + B[y-1] - c

print(value)

Submission status: Runtime Error

Solution code:
# coding: utf-8
A, B, M = map(int, input().split())
# print("A:", A, "B:", B, "M:", M)
a = list(map(int, input().split()))
# print("a:", a)
b = list(map(int, input().split()))
# print("b:", b)
z = [list(map(int, input().split())) for _ in range(M)]
# print("z:", z)
min_ = [a[i] + b[i] for i in range(max(A, B))]
# print("min:", min_)
for i in range(M):
    x, y, c = z[i]
    # print("x:", x, "y:", y, "c:", c)
    num = a[x - 1] + b[y - 1] - c
    # print("num:", num)
    min_.append(num)
# print(min_)
print(min(min_))

Submission status: Runtime Error

Solution code:
A, B, M = map(int, input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
value = min(a) + min(b)
for i in range(M):
    x,y,c = list(map(int, input().split()))
    if A[x-1] + B[y-1] - c < value:
        value = A[x-1] + B[y-1] - c

print(value)

Submission status: Runtime Error

Solution code:
a,b,m=map(int,input().split())
ak=list(map(int,input().split()))
bk=list(map(int,input().split()))
kei=[]
for i in range(m):
    x,y,c=map(int,input().split())
    pay=[ak[x]+bk[y]-c]
    kei+=pay
print(min(kei))

Submission status: Runtime Error

Solution code:
import sys

def main():
    input = sys.stdin.readline

    _, _, m = input().split()
    m = int(m)
    alist = input().split()
    blist = input().split()

    waribiki = [input().split() for _ in range(m)]
    
    res = [20000] * (len(alist)*len(blist) + m)
    count = 0
    for a in alist:
      for b in blist:
        res[count] = int(a)+int(b)
        count += 1

    for i in range(m):
        res[count] = int(alist[int(waribiki[i][0])-1]) + int(blist[int(waribiki[i][1])-1]) - int(waribiki[i][2])
        count += 1
      
    print(min(res))


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
A, B, M = map(int, input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
value = min(a) + min(b)
for i in range(M):
    x,y,c = list(map(int, input().split()))
    if A[x] + B[y] - c < value:
        value = A[x] + B[y] - c

print(value)

Submission status: Runtime Error

Solution code:
def main():
    import sys
    input=sys.stdin.readline
    sys.setrecursionlimit(10**9)

    A,B,M = list(map(int,input().split()))
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))
    x = [list(map(int,input().split())) for _ in range(M)]

    ans = min(a)+min(b)
    for i1,i2,discount in x:
        sum = a[i1-1]+a[i2-1]-discount
        ans = min(ans,sum)

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
zyouken = [int(i) for i in input().split()]
reizouko = [int(a) for a in input().split()]
densirenzi = [int(b) for b in input().split()]
minkouho = min(reizyouko) + min(densirenzi)
while zyouken[2] > 0:
    waribiki = [int(w) for w in input().split()]
    mink = reizyouko[waribiki[0]] + densirenzi[waribiki[1]] - waribiki[2]
    if mink < minkouho:
        minkouho = mink
print(minkouho)

Submission status: Runtime Error

Solution code:
A , B , M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = []
for i in range(M-1):
    q = list(map(int, input().split()))
    x = a[q[0]-1] + b[q[1]-1] - q[2]
    ans.append(x)
print(min(ans))

Submission status: Runtime Error

Solution code:
i=list(map(int, input().split()))
a=list(map(int, input().split()))
b=list(map(int, input().split()))
A=i[0]
B=i[1]
M=i[2]
x = []
y = []
c = []
for i in range(M):
    x1,y1,c1=[int(i) for i in input().split()]
    x.append(x1)
    y.append(y1)
    c.append(c1)
d=200001
e=100001
f=100001
for k in range (A):
    if a[k]<e:
        e=a[k]

for l in range (B):
    if b[k]<f:
        f=b[k]
d=e+f

for n in range (M):
    if a[x[n]]+b[y[n]]-c[n]<d:
        d= a[x[n]]+b[y[n]]-c[n]
print(d)

Submission status: Runtime Error

Solution code:
a,b,m=map(int,input().sprit())
ak=list(map(int,input().split()))
bk=list(map(int,input().split()))
kei=[]
for i in range(m):
    x,y,c=map(int,input().split())
    pay=ak[x]+bk[y]-c
    kei+=pay
print(mim(kei))

Submission status: Runtime Error

Solution code:
import sys

def main():
    # input = sys.stdin.readline

    _, _, m = input().split()
    m = int(m)
    alist = input().split()
    blist = input().split()

    waribiki = [input().split() for _ in range(m)]
    
    res = [None] * (len(alist)*len(blist) + m)
    count = 0
    for a in alist:
      for b in blist:
        res[count] = int(a)+int(b)
        count += 1

    for i in range(m):
        res[count] = int(alist[int(waribiki[i][0])-1]) + int(blist[int(waribiki[i][1])-1]) - int(waribiki[i][2])
        count += 1
      
    print(min(res))


if __name__ == '__main__':
    main()