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.

Solution (Python):
a,b,m=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
l=[list(map(int,input().split())) for _ in range(m)]
ans=min(a)+min(b)
for x,y,c in l:
    ans=min(ans,a[x-1]+b[y-1]-c)
print(ans)

Solution (Python):
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 i in range(M)]

price = min(a) + min(b)

for e in z:
    tmp_price = a[e[0]-1] + b[e[1]-1] - e[2]

    if(price > tmp_price):
        price = tmp_price

print(price)

Solution (Python):
A,B,M=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
nooff=sorted(a)[0]+sorted(b)[0]
withoff=[]
for i in range(M):
  x,y,c=map(int,input().split())
  off=a[x-1]+b[y-1]-c
  withoff.append(off)
print(min(sorted(withoff)[0],nooff))

Solution (Python):
a,b,m=map(int,input().split())
reizoko=list(map(int,input().split()))
renji=list(map(int,input().split()))
ans=min(reizoko)+min(renji)
for i in range(m):
    x,y,c=map(int,input().split())
    cost=reizoko[x-1]+renji[y-1]-c
    ans=min(ans,cost)
print(ans)

Solution (Python):
import sys
import itertools

import time
import math
import heapq
from collections import defaultdict
from collections import Counter
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines



A, B, M = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

ans = INF
for i in range(M):
    x, y, c = map(int, input().split())
    x -= 1
    y -= 1
    now = A[x] + B[y] - c
    ans = min(now, ans)
min_a = min(A)
min_b = min(B)
ans = min(ans, min_a + min_b)
print(ans)

Solution (Python):
A,B,M=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=[]
d=[]
for i in range(M):
    c.append(list(map(int,input().split())))
C=min(a)+min(b)
for i in range(0,M):
    d.append(a[(c[i][0]-1)]+b[(c[i][1]-1)]-c[i][2])
D=min(d)
print(min(C,D))

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

cost = []
cost.append(min(a) + min(b))
for x, y, c in xyc:
    tmp = a[x - 1] + b[y - 1] - c
    cost.append(tmp)
print(min(cost))

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


ans = min(a) + min(b)
for _ in range(m):
    x, y, c = map(int, input().split())
    ans = min(ans, a[x-1] + b[y-1] - c)

print(ans)

Solution (Python):
a,b,m = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
ans = min(a) + min(b)
for _ in range(m):
    x,y,c = map(int,input().split())
    ans = min(ans, a[x-1] + b[y-1] - c)
print(ans)

Solution (Python):

A,B,M = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
X = []
Y = []
C = []
for i in range(M):
    x,y,c = map(int,input().split())
    X.append(x)
    Y.append(y)
    C.append(c)


pay_sale = [a[i-1]+b[j-1]-k for i,j,k in zip(X,Y,C)]
pay_ticket = min(pay_sale) 

pay = min(a) + min(b)
print(min(pay,pay_ticket))

Solution (Python):
a, b, m = map(int,input().split())
rei = list(map(int,input().split()))
den = list(map(int,input().split()))
ans = [min(rei) + min(den)]
for i in range(m):
    x,y,c = map(int,input().split())
    ans.append(rei[x-1] + den[y-1] - c)
    
print(min(ans))

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

Solution (Python):
import numpy as np

lenA, lenB, M = map(int, input().split())

A = np.array(list(map(int, input().split())))
B = np.array(list(map(int, input().split())))
X = np.zeros((M, 3), dtype=int)

for i in range(M):
    X[i] = list(map(int, input().split()))

ans = min(A) + min(B)

for xi in X:
    tmp = A[xi[0] - 1] + B[xi[1] - 1] - xi[2]
    ans = min(ans, tmp)

print(ans)

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

ans = float('inf')
for i in range(M):
    x, y, c = map(int, input().split())
    ans = min(ans, a[x-1] + b[y-1] - c)
ans = min(ans, min(a) + min(b))
print(ans)

Solution (Python):
import math


def resolve():
    import sys
    input = sys.stdin.readline
    
    

    abm = [int(x) for x in input().rstrip().split(" ")]
    a_list = [int(x) for x in input().rstrip().split(" ")]
    b_list = [int(x) for x in input().rstrip().split(" ")]

    
    ans = min(a_list) + min(b_list)

    for i in range(abm[2]):
        xyc = [int(x) for x in input().rstrip().split(" ")]
        price = a_list[xyc[0] - 1] + b_list[xyc[1] - 1] - xyc[2]
        if price < ans:
            ans = price

    print(ans)

if __name__ == "__main__":
    resolve()

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

res = min(a) + min(b)
for _ in range(M):
  x, y, c = map(int, input().split())
  discounted_v = a[x-1] + b[y-1] - c
  if discounted_v < res: res = discounted_v
  
print(res)

Solution (Python):
_, _, M = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
xyc = [tuple(map(int, input().split())) for i in range(M)]
print(min([min(A)+min(B)]+[A[x-1]+B[y-1]-c for x, y, c in xyc]))

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

ans = min(a) + min(b)

for _ in range(M):
  x, y, c = map(int, input().split())
  cost = a[x - 1] + b[y - 1] - c
  ans = min(ans, cost)

print(ans)

Solution (Python):
A,B,M=map(int,input().split())
alist=list(map(int,input().split()))
blist=list(map(int,input().split()))
 
answer=min(alist)+min(blist)
for _ in range(M):
  x,y,c=map(int,input().split())
  disc=alist[x-1]+blist[y-1]-c
  answer=min(answer,disc)
  
print(answer)

Solution (Python):
A,B,M=map(int,input().split())
alist=list(map(int,input().split()))
blist=list(map(int,input().split()))

answer=min(alist)+min(blist)
for _ in range(M):
  x,y,c=map(int,input().split())
  disc=alist[x-1]+blist[y-1]-c
  answer=min(answer,disc)
  
print(answer)

Solution (Python):
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a.insert(0, 10**6)
b.insert(0, 10**6)
xyc = [list(map(int, input().split())) for _ in range(M)]

ans = min(a) + min(b)

for n in xyc:
    ans = min(ans, a[n[0]] + b[n[1]] - n[2])

print(ans)

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

xyc= [list(map(int, input().split())) for _ in range(M)]

minmoney = min(a) + min(b)

for obj in xyc:
    summoney = a[obj[0] - 1] + b[obj[1] - 1] - obj[2]
    minmoney = min(minmoney, summoney)

print(minmoney)

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

ans = min(a) + min(b)
for i in range(M):
    x, y, c = map(int, input().split())
    p = a[x-1] + b[y-1] - c
    if p < ans:
        ans = p
print(ans)

Solution (Python):
f=lambda:map(int,input().split())
A,B,m=f()
a=list(f())
b=list(f())
ans=min(a)+min(b)
for _ in range(m):
    x,y,c=f()
    ans=min(ans,a[x-1]+b[y-1]-c)
print(ans)

Solution (Python):
f=lambda:map(int,input().split())
A,B,m=f()
a=list(f())
b=list(f())
ans=min(a)+min(b)
for _ in range(m):
    x,y,c=f()
    ans=min(ans,a[x-1]+b[y-1]-c)
print(ans)

Solution (Python):
A, B, M = [int(a) for a in input().split()]
a = [int(ai) for ai in input().split()]
b = [int(bi) for bi in input().split()]
x = []
y = []
c = []
for _ in range(M):
    xi, yi, ci = [int(xyc) for xyc in input().split()]
    x.append(xi)
    y.append(yi)
    c.append(ci)

min_price = min(a) + min(b)
for i in range(M):
    price = a[x[i]-1] + b[y[i]-1] - c[i]
    min_price = min(min_price, price)

print(min_price)

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

A = list(map(int,input().split()))
B = list(map(int,input().split()))

ans = min(A)+min(B)

for i in range(m):
  x,y,c = map(int,input().split())
  cost = A[x-1] + B[y-1] - c
  if cost < ans:
    ans = cost

print(ans)

Solution (Python):
A,B,M=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
D=[]
for i in range(M):
    D.append(list(map(int,input().split())))
    
S=min(a)+min(b)
P=[]
for i in range(M):
    P.append(a[D[i][0]-1]+b[D[i][1]-1]-D[i][2])
P.append(S)
print(min(P))

Solution (Python):
A, B, M = map(int, input().split())
*a, = map(int, input().split())
*b, = map(int, input().split())
ans = 10**20

for _ in range(M):
    x, y, c = map(int, input().split())
    ans = min(ans, a[x-1]+b[y-1]-c)

a.sort()
b.sort()

ans = min(ans, a[0]+b[0])
print(ans)

Solution (Python):
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):
    x, y, c = map(int,input().split())
    z = a[x - 1] + b[y - 1] - c
    ans.append(z)
z = min(a) + min(b)
ans.append(z)
ans = sorted(ans)
print(ans[0])

Solution (Python):
a, b, m = map(int, input().split())
list_a = list(map(int, input().split()))
list_b = list(map(int, input().split()))
total = min(list_a) + min(list_b)
for i in range(m):
    x, y, c = map(int, input().split())
    price = list_a[x - 1] + list_b[y - 1] - c
    total = min(price, total)
print(total)

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

ans = 10**9

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

if min(a) + min(b) < ans:
    ans = min(a) + min(b)

print(ans)

Solution (Python):
A,B,M=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
List=[list(map(int,input().split())) for i in range(M)]
minn=min(a)+min(b)

for i in range(M):
    minn=min(minn,a[List[i][0]-1]+b[List[i][1]-1]-List[i][2])

print(minn)

Solution (Python):
a,b,m = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
l = [list(map(int,input().split())) for i in range(m)]
x,y,c = [list(i) for i in zip(*l)]
p = min(a) + min(b)

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

print(p)

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

result = min(a) + min(b)
for _ in range(M):
    x, y, c = map(int, input().split())
    discount = a[x-1] + b[y-1] - c
    result = min(result, discount)

print(result)

Solution (Python):
a, b, m = map(int, input().split())
arr_a = list(map(int, input().split()))
arr_b = list(map(int, input().split()))
cost = []
for i in range(m):
  x, y, c = map(int, input().split())
  cost.append(arr_a[x - 1] + arr_b[y - 1] - c)
cost.append(min(arr_a) + min(arr_b))
ans = min(cost)
print(ans)

Solution (Python):

a, b, m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = min(a) + min(b)
for _ in range(m):
    x, y, c = map(int, input().split())
    x -= 1
    y -= 1
    ans = min(ans, a[x] + b[y] - c)
print(ans)

Solution (Python):
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
xyc = [list(map(int, input().split())) for _ in range(M)]
ans_kouho = [min(a)+min(b)] + [a[x-1]+b[y-1]-c for x, y, c in xyc]
print(min(ans_kouho))

Solution (Python):

A,B,M = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
Sum = float("inf")
for i in range(M):
    x,y,c = map(int,input().split())
    if a[x-1]+b[y-1]-c < Sum:
        Sum = a[x-1]+b[y-1]-c
    
a.sort()
b.sort()
if a[0]+b[0] < Sum:
    Sum = a[0]+b[0]
print(Sum)

Solution (Python):
a,b,m = map(int,input().split())
a_li = list(map(int,input().split()))
b_li = list(map(int,input().split()))
cost = min(a_li) + min(b_li)
for i in range(m):
  x,y,c = map(int,input().split())
  price = a_li[x-1] + b_li[y-1] - c
  if price < cost:
    cost = price
print(cost)

Solution (Python):
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 i in range(M)]

ans = [min(a) + min(b)]
for x in X:
    a_idx, b_index, c = x
    ans.append(a[a_idx - 1] + b[b_index - 1] - c)

print(min(ans))

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

Solution (Python):
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
cost = [0] * M
for i in range(M) :
    x, y, c = map(int, input().split())
    cost[i] = a[x-1] + b[y-1] - c
a = sorted(a) ; b = sorted(b)
print(min(min(cost),a[0]+b[0]))

Solution (Python):
a,b,m=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 i in range(m):
  ans=min(ans,(a[x[i][0]-1]+b[x[i][1]-1]-x[i][2]))

print(ans)

Solution (Python):
import sys
input = sys.stdin.readline

a,b,m=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 i in range(m):
  ans=min(ans,(a[x[i][0]-1]+b[x[i][1]-1]-x[i][2]))

print(ans)

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

ans = min(a)+min(b)
for i in range(M):
    c, d, e = map(int, input().split())
    ans = min(ans, a[c-1]+b[d-1]-e)
print(ans)

Solution (Python):
import sys
input=sys.stdin.readline
A,B,M=list(map(int,input().split()))
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=[]
for i in range(M):
    xi,yi,ci=list(map(int,input().split()))
    c.append(a[xi-1]+b[yi-1]-ci)
a.sort()
b.sort()
c.sort()
print(min(a[0]+b[0],c[0]))

Solution (Python):
a,b,m = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
ans = min(A)+min(B)
for _ in range(m):
    x,y,c = map(int,input().split())
    ans = min(ans,A[x-1]+B[y-1]-c)
print(ans)

Solution (Python):
A, B, M = input().split(' ')
A = int(A)
B = int(B)
M = int(M)
a = input().split(' ')
a = [int(a[i]) for i in range(A)]
b = input().split(' ')
b = [int(b[i]) for i in range(B)]
cost = min(a) + min(b)
for i in range(M):
  x, y, c = input().split(' ')
  x = int(x)-1
  y = int(y)-1
  c = int(c)
  if a[x] + b[y] - c < cost:
    cost = a[x] + b[y] - c
print(cost)

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

a.sort()
b.sort()
ans = min(ans,a[0] + b[0])
print(ans)

Solution (Python):
a,b,M=map(int,input().split())
*A,=map(int,input().split())
*B,=map(int,input().split())
xyc=[list(map(int,input().split()))for _ in range(M)]

ans=min(A)+min(B)
for x,y,c in xyc:
    ans=min(ans,A[x-1]+B[y-1]-c)
print(ans)

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

ans = min(A) + min(B)

for _ in range(m):
    x, y, c = map(int, input().split())
    x -= 1
    y -= 1
    cnt = A[x] + B[y] - c
    ans = min(ans, cnt)

print(ans)

Solution (Python):
A,B,N=list(map(int,input().split()))
listA=list(map(int,input().split()))
listB=list(map(int,input().split()))
ma=sorted(listA)
mb=sorted(listB)
M=min(ma)+min(mb)
for i in range(N):
  x,y,c=list(map(int,input().split()))
  ans=listA[x-1]+listB[y-1]-c
  if ans<M:
    M=ans
print(M)

Solution (Python):
NA, NB, M = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))

res = 1_000_000_000
for i in range(M):
    x, y, c = list(map(int, input().split()))
    res = min(A[x - 1] + B[y - 1] - c, res)

res = min(min(A) + min(B), res)
print(res)

Solution (Python):
A,B,M = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
ans = 1000000
for i in range(M):
  x,y,c = map(int,input().split())
  ans =  min(ans,a[x-1]+b[y-1]-c)
a.sort()
b.sort()
ans = min(ans,a[0]+b[0])
print(ans)

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

Solution (Python):
a,b,m=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
ans=10**6
for i in range(m):
    x,y,c=map(int,input().split())
    ans=min(ans,A[x-1]+B[y-1]-c)
print(min(ans,min(A)+min(B)))

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

vals = []
for _ in range(M):
    i, j, v = map(int, input().split())
    vals.append( a[i - 1] + b[j - 1] - v)

vals.append(min(a) + min(b))
print(min(vals))

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


total = min(a) + min(b)

for i in range(0,M,1):
    c = list(map(int,input().split()))  
    kakaku = a[c[0]-1]+ b[c[1]-1] - c[2]
    if total > kakaku:
        total = kakaku

print(total)

Solution (Python):
A,B,M = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
p = min(A) + min(B)
for _ in range(M):
    x,y,c = map(int, input().split())
    p = min(p, A[x-1]+B[y-1]-c)
print(p)

Solution (Python):
import sys

A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = []
for e in sys.stdin:
  c.append(list(map(int, e.split())))

ans = min(a) + min(b)

for i in range(len(c)):
  temp_val = a[c[i][0]-1] + b[c[i][1]-1] - c[i][2]
  if temp_val < ans:
    ans = temp_val

print(ans)

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

r = tuple(map(int,input().split()))
d = tuple(map(int,input().split()))

ans = min(r)+min(d)

for i in range(m):
    x,y,c = map(int,input().split())
    ans = min(ans,r[x-1]+d[y-1]-c)
    
print(ans)

Solution (Python):
a,b,m = map(int, input().split())
aprice = list(map(int, input().split()))
bprice = list(map(int, input().split()))
c = sorted(aprice)
d = sorted(bprice)
e = c[0]+d[0]
f  =0
for i in range(m):
  x,y,k = map(int, input().split())
  f =aprice[x-1]+bprice[y-1]-k
  if(e>f):
    e = f
print(e)

Solution (Python):
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):
    x,y,c = map(int, input().split())
    ans += [A[x-1] + B[y-1] - c]
ans += [min(A) + min(B)]

print(min(ans))

Solution (Python):
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):
    x,y,c = map(int, input().split())
    ans += [A[x-1] + B[y-1] - c]
ans += [min(A) + min(B)]

print(min(ans))

Solution (Python):
def resolve():
    a, b, m = map(int, input().split())
    a_list = list(map(int, input().split()))
    b_list = list(map(int, input().split()))
    ans = min(a_list) + min(b_list)
    for _ in range(m):
        x, y, c = map(int, input().split())
        ans = min(ans, a_list[x-1]+b_list[y-1]-c)
    print(ans)
resolve()

Solution (Python):
a,b,m=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
ans=min(A)+min(B)
for i in range(m):
    x,y,c=map(int,input().split())
    num=A[x-1]+B[y-1]-c
    ans=min(num,ans)
print(ans)

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

ans = min(a)+min(b)

for _ in range(M):
    x, y, c = map(int, input().split())
    ans = min(a[x-1]+b[y-1]-c, ans)

print(ans)

Solution (Python):
(A, B, M), aa, bb, *xyc = [list(map(int, s.split())) for s in open(0)]

ans = min(aa)+min(bb)

for x, y, c in xyc:
    ans = min(ans, aa[x-1]+bb[y-1]-c)

print(ans)

Solution (Python):
a, b, M = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
ans = min(A)+min(B)
for _ in range(M):
    x, y, c = map(int, input().split())
    ans = min(ans, A[x-1]+B[y-1]-c)

print(ans)

Solution (Python):
a, b, m = map(int, input().split())
a_s = list(map(int, input().split()))
b_s = list(map(int, input().split()))
m_s =[]

for _ in range(m):
    m_s.append(list(map(int, input().split())))

mini = min(a_s) + min(b_s)

for am, bm, sale in m_s:
    mini = min(mini, a_s[am-1]+b_s[bm-1]-sale)

print(mini)

Solution (Python):
A,B,M = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
ans = float("inf")
for i in range(M):
  x,y,c = map(int,input().split())
  ans = min(a[x-1]+b[y-1]-c,ans)
  
ans = min(ans,min(a)+min(b))
    
print(ans)

Solution (Python):
A, B, M = map(int, input().split())

price_A = list(map(int, input().split()))
price_B = list(map(int, input().split()))

ans = min(price_A)+min(price_B)

for m in range(M):
  x, y, c = map(int, input().split())
  p1 = price_A[x-1] + price_B[y-1] - c
  if p1 <= ans: ans=p1

print(ans)

Solution (Python):
import sys
input = sys.stdin.readline

a, b, m = [int(w) for w in input().split()]
a_li = [int(w) for w in input().split()]
b_li = [int(w) for w in input().split()]

ans = min(a_li) + min(b_li)

for i in range(m):
    x, y, c = [int(w) for w in input().split()]
    t = a_li[x - 1] + b_li[y - 1] - c
    ans = min(ans, t)

print(ans)

Solution (Python):
A,B,M=map(int,input().split())

X=[10**10]+list(map(int,input().split()))
Y=[10**10]+list(map(int,input().split()))

K=min(X)+min(Y)

for _ in range(M):
    x,y,c=map(int,input().split())
    K=min(K,X[x]+Y[y]-c)
print(K)

Solution (Python):
A,B,M=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=sorted(a)
d=sorted(b)
ans=c[0]+d[0]
for i in range(M):
  x,y,c=map(int,input().split())
  temp=a[x-1]+b[y-1]-c
  ans=min(ans,temp)
print(ans)

Solution (Python):
A,B,M = map(int,input().split())
a_price = list(map(int,input().split()))
b_price = list(map(int,input().split()))

dis = []
for _ in range(M):
  dis.append(list(map(int,input().split())))

total = min(a_price)+min(b_price)

dis_total = []
for k in range(M):
  dis_total.append(a_price[dis[k][0]-1]+b_price[dis[k][1]-1]-dis[k][2])

if total <= min(dis_total):
  print(total)
else:
  print(min(dis_total))

Solution (Python):









import sys
input = sys.stdin.readline

A, B, M = map(int, input().split())
List_A = list(map(int, input().split()))
List_B = list(map(int, input().split()))
List_discount = [list(map(int, input().split())) for i in range(M)]


ans = 2 * 10**5
for d in List_discount:
    
    p = List_A[d[0]-1] + List_B[d[1]-1] - d[2]
    ans = min(ans, p)
no_discount = min(List_A) + min(List_B)
ans = min(ans, no_discount)
print(ans)

Solution (Python):
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
discount = list(map(int, input().split()) for _ in range(M))

ans = min(a) + min(b)

for x, y, c in discount:
    tmp = a[x - 1] + b[y - 1] - c
    if tmp < ans:
        ans = tmp

print(ans)

Solution (Python):
A, B, M = map(int, input().split())
Frz = list(map(int, input().split()))
Mic = list(map(int, input().split()))
C = []

for _ in range(M):
    x, y, c = map(int, input().split())
    x -= 1
    y -= 1
    C.append((x,y,c))

minF = min(Frz)
minM = min(Mic)
ans = minF + minM

for x, y, z in C:
    tmp = Frz[x] + Mic[y] - z
    if tmp < ans:
        ans = tmp

print(ans)

Solution (Python):
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
res = min(a) + min(b)
for _ in range(M):
    x, y, c = map(int, input().split())
    res = min(res, a[x-1] + b[y-1] - c)
print(res)

Solution (Python):
a,b,m=map(int,input().split())
f=list(map(int,input().split()))
w=list(map(int,input().split()))
money=min(f)+min(w)
for i in range(m):
    x,y,c=map(int,input().split())
    if f[x-1]+w[y-1]-c<money:
        money=f[x-1]+w[y-1]-c
print(money)

Solution (Python):
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 _ in range(M):
    x, y, c = map(int, input().split())
    discount_price = a[x-1] + b[y-1] - c
    if min_price > discount_price:
        min_price = discount_price
        
print(min_price)

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

Solution (Python):
a,b,m = map(int,input().split())
al = list(map(int,input().split()))
bl = list(map(int,input().split()))
yasuiyo = min(al) + min(bl)
ans = []
for i in range(m):
  x,y,c = map(int,input().split())
  ans.append(al[x-1] + bl[y-1] - c)

print(min(min(ans),yasuiyo))

Solution (Python):
a,b,m = map(int,input().split())
al = list(map(int,input().split()))
bl = list(map(int,input().split()))
yasuiyo = min(al) + min(bl)
ans = []
for i in range(m):
  x,y,c = map(int,input().split())
  ans.append(al[x-1] + bl[y-1] - c)

print(min(min(ans),yasuiyo))

Solution (Python):
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):
    x,y,c = map(int,input().split())
    min_price = min(min_price,a[x-1]+b[y-1]-c)
print(min_price)

Solution (Python):
import sys
read = sys.stdin.read
def main():
    a, b, m = map(int, input().split())
    al = tuple(map(int, input().split()))
    bl = tuple(map(int, input().split()))
    r = min(al) + min(bl)
    m = map(int, read().split())
    xyc = zip(m, m, m)
    for x, y, c in xyc:
        r = min(r, al[x-1] + bl[y-1] - c)
    print(r)

if __name__ == '__main__':
    main()

Solution (Python):
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 i in range(M)]

ans = [min(a) + min(b)]
for x in X:
    a_idx, b_index, c = x
    ans.append(a[a_idx - 1] + b[b_index - 1] - c)

print(min(ans))

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

e=min(a)+min(b)

for _ in range(M):
    x,y,c=map(int,input().split())
    f=a[x-1]+b[y-1]-c
    e=min(e,f)

print(e)

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

e=min(a)+min(b)

for _ in range(M):
    x,y,c=map(int,input().split())
    f=a[x-1]+b[y-1]-c
    e=min(e,f)

print(e)

Solution (Python):
a,b,m = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
count = min(a)+min(b)
for i in range(m):
  x,y,c = map(int,input().split())
  if count > a[x-1]+b[y-1]-c:
    count = a[x-1]+b[y-1]-c
    
print(count)

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

Solution (Python):
a, b, m = map(int, input().split())
reizo = list(map(int, input().split()))
renji = list(map(int, input().split()))
p = [list(map(int,input().split())) for i in range(m)]
ans = []
for i in range(m):
  cost = reizo[p[i][0] - 1] + renji[p[i][1] - 1] - p[i][2]
  ans.append(cost)
ans.append(min(reizo) + min(renji))
print(min(ans))

Solution (Python):
def resolve():
    x = []
    y = []
    c = []
    ans = []
    A, B, M = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    for _ in range(M):
        X, Y, C = map(int, input().split())
        x.append(X)
        y.append(Y)
        c.append(C)
    ans.append(min(a)+min(b))
    for i in range(M):
        ans.append(a[x[i]-1]+b[y[i]-1]-c[i])
    print(min(ans))
resolve()

Solution (Python):
an, bn, m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

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

print(r)

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

r=min(A)+min(B)
for i in range(m):
  x,y,c=map(int,input().split())
  r=min(r,A[x-1]+B[y-1]-c)

print(r)

Solution (Python):
a, b, m = map(int, input().split())
lista = list(map(int, input().split()))
listb = list(map(int, input().split()))

ans = min(lista)+min(listb)

for i in range(m):
    x, y, c = map(int, input().split())
    dprice = lista[x-1]+listb[y-1] - c
    if ans > dprice:
        ans = dprice

print(ans)

Solution (Python):
A,B,M=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
ans=10**6
for i in range(M):
    x,y,c=map(int,input().split())
    ans=min(ans,(a[x-1]+b[y-1])-c)
a.sort(key=int)
b.sort(key=int)
for i in range(min(A,B)):
    if a[i]+b[i]>=ans: break
    ans=min(ans,a[i]+b[i])
print(ans)