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()))

min = sorted(a)[0] + sorted(b)[0]

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

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()]
ans = float('inf')
for _ in range(M):
    x, y, c = [int(i) for i in input().split()]
    ans = min(ans, A[x-1] + B[y-1] - c)
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()))
 
ans = min(a)+min(b)
 
for i in range(M):
    x,y,z = map(int,input().split())
    s = a[x-1]+b[y-1]-z
    ans = (s if s < ans else 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 i in range(M):
    c =list(map(int,input().split()))
    s = a[c[0]-1]+b[c[1]-1]-c[2]
    ans = min(s,ans)

print(ans)

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

min = min(a)+min(b)

for i in range(M):
    c =list(map(int,input().split()))
    s = a[c[0]-1]+b[c[1]-1]-c[2]
    min = (s if s < min else min)

print(min)

Solution (Python):


import sys
input = sys.stdin.readline

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

As = list(map(int, input().split()))
Bs = list(map(int, input().split()))

ans = min(As) + min(Bs)

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

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()))

minP = min(a) + min(b)

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

print(minP)

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

Solution (Python):
a,b,m = map(int,input().split())
al = list(map(int,input().split()))
bl = list(map(int,input().split()))
disc = [[]]*m
for i in range(m):
  disc[i] = list(map(int,input().split()))
mina = 100000
minb = 100000
for i in range(a):
  mina = min(mina,al[i])
for i in range(b):
  minb = min(minb,bl[i])
total = mina+minb
for i in range(m):
  total = min(total,al[disc[i][0]-1]+bl[disc[i][1]-1]-disc[i][2])
print(total)

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

p=min(a)+min(b)

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

print(p)

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(a[x-1]+b[y-1]-c,ans)
print(ans)

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

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

prm_min = min(la) + min(lb)

lcost = list()
for i in range(M):
    x, y, c = map(int, input().split())
    lcost.append(la[x-1] + lb[y-1] - c)

print(min(min(lcost), prm_min))

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

amin = min(a)
bmin = min(b)
ans = amin + bmin
for c_ in c:
    tmp = a[c_[0]-1] + b[c_[1]-1] - c_[2]
    ans = min(ans,tmp)

print(ans)

Solution (Python):
A,B,M=map(int, input().split())
As=list(map(int, input().split()))
Bs=list(map(int, input().split()))
List=[]
for i in range(M):
  List.append(list(map(int, input().split())))

ans=min(As)+min(Bs)
for l in List:
  candidate=As[l[0]-1]+Bs[l[1]-1]-l[2]
  ans = min(ans, candidate)
print(ans)

Solution (Python):
A,B,M=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
low=min(a)+min(b)
cost=[]
for i in range(M):
  x,y,c=map(int,input().split())
  cost.append(a[x-1]+b[y-1]-c)
  
print(min(low,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())
    tmp = a[x-1] + b[y-1] - c
    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()))
x = list()
y = list()
c = list()
for i in range(M):
    _x, _y, _c = map(int, input().split())
    x.append(_x-1)
    y.append(_y-1)
    c.append(_c)
ans = min(a) + min(b)
for i in range(M):
    ans = min(ans, a[x[i]]+b[y[i]]-c[i])
print(ans)

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

a = list(map(int,input().split()))
b = list(map(int,input().split()))

mi = min(a) + min(b)

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

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

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()))
c = [list(map(int,input().split())) for _ in range(m)]
ans = min(a)+min(b)
for i in range(m):
    ans = min(ans, a[c[i][0]-1]+b[c[i][1]-1]-c[i][2])
print(ans)

Solution (Python):
def solve():
    A,B, M = map(int, input().split())
    a_kind = list(map(int, input().split()))
    b_kind = list(map(int, input().split()))
    Coupon =  [list(map(int, input().split())) for _ in range(M)]
    ans = min(a_kind) + min(b_kind)

    for x,y,disc in Coupon:
        ans = min(ans, a_kind[x-1] + b_kind[y-1] - disc)
    print(ans)



if __name__ == '__main__':
    solve()

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

ans = min(a) + min(b)

for i in range(M):
  ans = min(ans, a[m[i][0]-1] + b[m[i][1]-1] - m[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()))
c=[min(a)+min(b)]
for i in range(M):
    a1,b1,c1 =map(int,input().split())
    d=a[a1-1]+b[b1-1]-c1
    c.append(d)
print(min(c))

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())
    x-=1; y-=1
    point=a[x]+b[y]-c
    ans=min(point,ans)
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 m in range(M):
  x,y,c=map(int,input().split())
  X.append(x)
  Y.append(y)
  C.append(c)
no_coupon=min(a)+min(b)

sum=[]
for i in range(M):
  sum.append(a[X[i]-1]+b[Y[i]-1]-C[i])

with_coupon=min(sum)
print(min(no_coupon,with_coupon))

Solution (Python):
import sys

def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))

def DD2(d1,d2,init=0): return [[init]*d2 for _ in range(d1)]
def DD3(d1,d2,d3,init=0): return [DD2(d2,d3,init) for _ in range(d1)]

def to_bin(x: int) -> str: return format(x, 'b') 
def to_oct(x: int) -> str: return format(x, 'o') 
def to_hex(x: int) -> str: return format(x, 'x') 
MOD=10**9+7
def divc(x,y) -> int: return -(-x//y)
def divf(x,y) -> int: return x//y
def gcd(x,y):
    while y: x,y = y,x%y
    return x
def lcm(x,y): return x*y//gcd(x,y)
def enumerate_divs(n):
    """Return a tuple list of divisor of n"""
    return [(i,n//i) for i in range(1,int(n**0.5)+1) if n%i==0]
def get_primes(MAX_NUM=10**3):
    """Return a list of prime numbers n or less"""
    is_prime = [True]*(MAX_NUM+1)
    is_prime[0] = is_prime[1] = False
    for i in range(2, int(MAX_NUM**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i*2, MAX_NUM+1, i):
            is_prime[j] = False
    return [i for i in range(MAX_NUM+1) if is_prime[i]]

from itertools import accumulate as acc
from collections import deque, Counter
from heapq import heapify, heappop, heappush
from bisect import bisect_left



def main():
    a, b, m = MII()
    aa = MII()
    bb = MII()
    q = [MII() for _ in range(m)]
    minv = min(aa) + min(bb)
    for x,y,c in q:
        minv = min(minv, aa[x-1]+bb[y-1]-c)
    print(minv)

if __name__ == '__main__':
    main()

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())
    price = a[x - 1] + b[y - 1] - c
    ans = min(ans, price)

print(ans)

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

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

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

Solution (Python):


na,nb,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())
    tmp=a[x-1]+b[y-1]-c
    if tmp<ans:
        ans=tmp
print(ans)

Solution (Python):
import numpy as np

def multi_input():
    return map(int, input().split())

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

mn = np.inf
for x, y, c in C:
    mn = min(mn, a[x-1]+b[y-1]-c)
mn = min(mn, min(a)+min(b)) 
print(mn)

Solution (Python):
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 i in range(M):
  x, y, c = map(int, input().split())
  ans = min(ans, a_list[x-1] + b_list[y-1] - c)
print(ans)

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    a,b,m=map(int, input().split())
    la=list(map(int,input().split()))
    lb=list(map(int,input().split()))
    lm=[list(map(int,input().split())) for i in range(m)]
    nowari=min(la)+min(lb)
    warians=10**10
    for i in range(m):
        wari=la[(lm[i][0])-1]+lb[(lm[i][1])-1]-lm[i][2]
        if wari<warians:
            warians=wari
    print(min(nowari,warians))
resolve()

Solution (Python):
import itertools 

line1 = input().split()
rei = input().split()
rei =list(map(int,rei))
den =input().split()
den =list(map(int,den))
cupon =[list(map(int,input().split())) for i in range(int(line1[2]))]

rei_mi = min(rei)
den_mi =min(den)

no_total =rei_mi +den_mi

for s in range(int(line1[2])):
  yes_total =int(rei[cupon[s][0]-1]) +int(den[cupon[s][1]-1]) - cupon[s][2]
  if no_total > yes_total:
    no_total =yes_total
print(no_total)

Solution (Python):
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 = 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]-1] + b[y[i]-1] - c[i]
print(ans)

Solution (Python):
A,B,M=map(int,input().split())
a_1=list(map(int,input().split()))
b_1=list(map(int,input().split()))
L=[list(map(int,input().split())) for _ in range(M)]

count=[]
count.append(min(a_1)+min(b_1))

for k in range(M):
    count.append(a_1[L[k][0]-1]+b_1[L[k][1]-1]-L[k][2])

print(min(count))

Solution (Python):
A, B, M = list(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 i in range(M):
    x, y, c = list(map(int, input().split()))
    cost = a_list[x - 1] + b_list[y - 1] - c
    if cost < ans:
        ans = cost
        
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()))
L=[[int(j) for j in input().split()] for i in range(m)]

sortsec = lambda val : val[2]
L1=sorted(L,key=sortsec,reverse=True)
cnt=10**8
for i,j,k in L1:
    num=A[i-1]+B[j-1]-k
    cnt=min(cnt,num)
num=min(A)+min(B)
print(min(num,cnt))

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

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

Solution (Python):
a, b, m = map(int, input().strip().split())
as_ = list(map(int, input().strip().split()))
bs = list(map(int, input().strip().split()))
xyc = [list(map(int, input().strip().split())) for _ in range(m)]

min_no_discount = min(as_) + min(bs)

min_discount = 1e20
for x, y, c in xyc:
    min_discount = min(min_discount, as_[x - 1] + bs[y - 1] - c)

print(min(min_discount, min_no_discount))

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

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

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

min_ = min(min(C), min(A) + min(B))
print(min_)

Solution (Python):
import numpy as np
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()))

res = np.min(a) + np.min(b)

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

print(res)

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()]
mn = min(a)+min(b)
for i in range(m):
    x,y,c = map(int,input().split())
    res = a[x-1]+b[y-1]-c
    if mn > res:
        mn = res
print(mn)

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

smallest = min(a) + min(b)

for i in range(M):
    if a[xyc[i][0]-1] + b[xyc[i][1]-1] - xyc[i][2] < smallest:
        smallest = a[xyc[i][0]-1] + b[xyc[i][1]-1] - xyc[i][2]

print(smallest)

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

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

Solution (Python):
from statistics import median


from itertools import combinations 
from collections import deque
from collections import defaultdict
from fractions import gcd
import bisect










import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    a,b,m = readInts()
    A = readInts()
    B = readInts()
    ans = float('inf')
    for i in range(m):
        x,y,c = readInts()
        x -=1
        y -=1
        ans = min(ans,A[x] + B[y] - c)
    
    
    ans = min(ans,min(A) + min(B))
    print(ans)
if __name__ == '__main__':
  main()

Solution (Python):
A, B, M = (int(x) for x in input().split())
al = [int(x) for x in input().split()]
bl = [int(x) for x in input().split()]
ml = [[int(x) for x in input().split()] for _ in range(M)]
"""
price = []
for l in ml:
    price.append(al[l[0]-1] + bl[l[1]-1] - l[2])
for x in al:
    for y in bl:
        price.append(x+y)
"""
price = [al[l[0]-1] + bl[l[1]-1] - l[2] for l in ml] + [min(al)+min(bl)] 
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 _ 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):
A, B, M = map(int, input().split())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
ans = min(a) + min(b)
for _ in range(M):
    x, y, c = map(int, input().split())
    tmp = a[x - 1] + b[y - 1] - c
    ans = min(ans, tmp)
print(ans)

Solution (Python):
import sys


def readlines(n):
    for _ in range(n):
        x, y, c = map(int, input().split())
        yield x-1, y-1, c

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

    yield(min(a) + min(b))

    for x, y, c in readlines(M):
        a_ = a[x]
        b_ = b[y]

        yield a_ + b_ - c

print(min(main()))

Solution (Python):

A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
kingaku=[]
for i in range(M):
    x_input, y_input, c_input = map(int, input().split())
    kingaku.append(a[x_input-1]+b[y_input-1]-c_input)
kingaku.append(min(a)+min(b))

print(min(kingaku))

Solution (Python):
import sys

A, B, M = map(int, sys.stdin.readline().rstrip().split())
a = list(map(int, sys.stdin.readline().rstrip().split()))
b = list(map(int, sys.stdin.readline().rstrip().split()))
xyc = [list(map(int, sys.stdin.readline().rstrip().split())) for i in range(M)]
ans = min(a) + min(b)

for xyci in xyc:
    x, y, c = xyci
    tmp = a[x - 1] + b[y - 1] - c
    if ans > tmp:
        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()))
l=[]
for i in range(m):
  x,y,c=map(int,input().split())
  l.append(a[x-1]+b[y-1]-c)
l.append(min(a)+min(b))
print(min(l))

Solution (Python):
AA, BB, M = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
res = min(A) + min(B)
for i in range(M):
  x, y, c = list(map(int, input().split()))
  x-=1
  y-=1
  discount = A[x] + B[y] - c
  if discount < res:
    res = discount

print(res)

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

min_price = min(a_p) + min(b_p)

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

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

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()))
a_min=min(a)
b_min=min(b)
discount_m=10000000
for i in range(m):
    x,y,c=map(int,input().split())
    p=a[x-1]+b[y-1]-c
    if p<discount_m:
        discount_m=p
print(min(a_min+b_min,discount_m))

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)]

aMin = min(a)
bMin = min(b)
ans = aMin + bMin

for xycm in xyc:
    x = xycm[0] - 1
    y = xycm[1] - 1
    c = xycm[2]
    p = a[x] + b[y] - c

    if p < ans:
        ans = p

print(ans)

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)]


m = min(a) + min(b)
ans = []
ans.append(m)
for i in range(M):
    x = L[i][0]
    y = L[i][1]
    c = L[i][2]
    p = a[x - 1]
    k = b[y - 1]
    ans.append(p + k - c)

print(min(ans))

Solution (Python):
A,B,M=map(int,input().split(" "))
As=list(map(int,input().split(" ")))
Bs=list(map(int,input().split(" ")))
ans=min(As)+min(Bs)
for i in range(M):
  x,y,c=map(int,input().split(" "))
  ans=min(ans,As[x-1]+Bs[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()))
aa=sorted(a)
bb=sorted(b)
ans=aa[0]+bb[0]
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()))

xyc = [map(int, input().split()) for _ in range(M)]
x, y, c = [list(i) for i in zip(*xyc)]

price1 = min(a) + min(b)
price2 = []

for i in range(M):
  xi = x[i] - 1
  yi = y[i] - 1
  price_tmp = a[xi] + b[yi] - c[i]
  price2.append(price_tmp)
  
price2 = min(price2)

if price1 > price2:
  print(price2)
else:
  print(price1)

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()]

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

MIN = min(A) + min(B)
ans = min(ans, MIN)
print(ans)

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

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

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

total_min = min(a_list) + min(b_list)
for x,y,c in xyc_list:
    total = a_list[x-1] + b_list[y-1] - c
    if total_min > total:
        total_min = total

print(total_min)

Solution (Python):


A,B,M = map(int, input().split())
a = [int(x) for x in input().split()]
b = [int(y) for y in input().split()]
c = [[0 for k in range(3)] for k in range(M)]

m = 0
while m < M:
    c[m][0],c[m][1],c[m][2]= map(int, input().split())
    m = m + 1

result = min(a) + min(b)

i = 0
for i in range(M):
    num = a[c[i][0]-1] + b[c[i][1]-1]-c[i][2]
    if result > num:
        result = num
    i = i + 1

print(result)

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

A, B, M = MAP()
a = LIST()
b = LIST()
xyc = [LIST() for _ in range(M)]

sum = [min(a)+min(b)]
for i in range(M):
	sum.append(a[xyc[i][0]-1] + b[xyc[i][1]-1] - xyc[i][2])

print(min(sum))

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

a, b, m = map(int, readline().split())
aa = list(map(int, readline().split()))
bb = list(map(int, readline().split()))
xyc = [list(map(int, readline().split())) for _ in range(m)]
ans = float('inf')
for x, y, c in xyc:
    ans = min(aa[x - 1] + bb[y - 1] - c, ans)
aa.sort()
bb.sort()
print(min(ans, aa[0] + bb[0]))

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

mins = min(a) + min(b)
for i in range(M):
  ai, bi, ci = c[i]
  mins = min(mins, a[ai-1] + b[bi-1] - ci)
print(mins)

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

price=[0]*(M+1)
price[0]=min(a)+min(b)

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

print(min(price))

Solution (Python):


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
d=[]
for i in range(m):
 x[i],y[i],c[i]=map(int,input().split())
 d.append(a[x[i]-1]+b[y[i]-1]-c[i])
print(min(min(d),min(a)+min(b)))

Solution (Python):
a,b,m = map(int,input().split())
a_li = list(map(int,input().split()))
b_li = list(map(int,input().split()))
x_li=[list(map(int,input().split())) for _ in range(m)]
minprice = min(a_li) + min(b_li)
for i in x_li:
    price = a_li[i[0]-1] + b_li[i[1]-1] - i[2]
    minprice = min(minprice,price)
print(minprice)

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 = 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()))
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 i in range(M):
    x, y, c = map(int, input().split())
    cost = a[x-1] + b[y-1] -c
    if ans > cost:
        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()))
L = [[int(x) for x in input().split()] for _ in range(M)]

reg = min(a) + min(b)
for x, y, c in L:
    tmp = a[x-1] + b[y-1] - c
    reg = min(reg, tmp)
print(reg)

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

Solution (Python):
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    a,b,m=map(int,input().split())
    A=[int(_) for _ in input().split()]
    B=[int(_) for _ in 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)

if __name__=='__main__':
    main()

Solution (Python):
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    a,b,m=map(int,input().split())
    A=[int(_) for _ in input().split()]
    B=[int(_) for _ in 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)

if __name__=='__main__':
    main()

Solution (Python):
a,b,m = map(int,input().split())
a_inputs = [int(i) for i in input().split()]
b_inputs = [int(i) for i in input().split()]
x_inputs = [[int(j) for j in input().split()]for i in range(m)]

ans = min(a_inputs)+min(b_inputs)

for xyc in x_inputs:
    cost = a_inputs[xyc[0]-1]+b_inputs[xyc[1]-1]-xyc[2]
    if cost<ans:
        ans= cost
print(ans)

Solution (Python):
A, B, M = map(int, input().split())
a_li = list(map(int, input().split()))
b_li = list(map(int, input().split()))
min_cost = min(a_li) + min(b_li)

for i in range(M):
    x, y, discount = list(map(int, input().split()))
    a_idx = x - 1
    b_idx = y - 1
    cost = a_li[a_idx] + b_li[b_idx] - discount
    min_cost = min(min_cost, cost)

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 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()))
xyc = [list(map(int,input().split())) for _ in range(m)]


yes_m = a[xyc[0][0]-1]+b[xyc[0][1]-1] - xyc[0][2]

for i in range(1,m):
    if yes_m > a[xyc[i][0]-1]+b[xyc[i][1]-1] - xyc[i][2]:
        yes_m = a[xyc[i][0]-1]+b[xyc[i][1]-1] - xyc[i][2]

no_m = min(a)+min(b)

print(min(no_m,yes_m))

Solution (Python):
A,B,M=list(int(i) for i in input().split())
acost=list(int(i) for i in input().split())
bcost=list(int(i) for i in input().split())
mina=min(acost)
minb=min(bcost)
amount=10**19+1
for _ in range(M):
    x,y,c=list(int(i) for i in input().split())
    if (acost[x-1]+bcost[y-1]-c)<amount:
        amount=acost[x-1]+bcost[y-1]-c
if amount<=(mina+minb):
    print(amount)
else:
    print(mina+minb)