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(" "))
ar = list(map(int,input().split(" ")))
br = list(map(int,input().split(" ")))
A = min(ar) + min(br)
for i in range(m):
    l = list(map(int,input().split(" ")))
    B = (ar[l[0]-1] + br[l[1]-1]) - l[2]
    if A > B:
        A = B
print(A)

Solution (Python):
A,B,M=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
vch=[]
ac=10**15
for i in range(A):
    ac=min(ac,a[i])
bc=10**15
for i in range(B):
    bc=min(bc,b[i])
ans=ac+bc
for i in range(M):
    c=list(map(int,input().split()))
    ans=min(ans,a[c[0]-1]+b[c[1]-1]-c[2])
print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10000000)
from collections import defaultdict
from bisect import *
mod = 10**9+7

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)]
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 = list(map(int, input().split()))
AL = list(map(int, input().split()))
BL = list(map(int, input().split()))

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

Solution (Python):
r_cnt,d_cnt,w_cnt = map(int, input().split())
rei = list(map(int, input().split()))
den = list(map(int, input().split()))
wari = []
min_amount = 0
for i in range(w_cnt):
    a,b,c = map(int, input().split())
    amount = rei[a - 1] + den[b - 1] - c
    if i == 0 or amount < min_amount:
        min_amount = amount

amount = min(rei) + min(den)
if amount < min_amount:
    min_amount = amount
print(min_amount)

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



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

Solution (Python):
S = [int(e) for e in input().split()]
list_a =  [int(e) for e in input().split()]
list_b =  [int(e) for e in input().split()]

dis_list = []

for i in range(S[2]):
    dis_list.append([int(e) for e in input().split()])

min_num1 = min(list_a) + min(list_b)

min_num2_list = []

for l in dis_list:
    min_num2_list.append(list_a[l[0]-1] + list_b[l[1]-1] - l[2])

min_num2 = min(min_num2_list)

if min_num1 > min_num2:
    print(min_num2)
else:
    print(min_num1)

Solution (Python):
A, B, m = map(int, input().split())
aa = list(map(int, input().split()))
bb = list(map(int, input().split()))
xyc = [list(map(int, input().split())) for _ in range(m)]

mx = min(aa) + min(bb) 
for i in range(m):
    x, y, c = xyc[i]
    x -= 1
    y -= 1
    mx = min(mx, aa[x]+bb[y]-c)
print(mx)

Solution (Python):
A, B, M = input().split()
a_num = input()
b_num = input()
number = [input() for i in range(int(M))]

a_cost = []
b_cost = []

for a in a_num.split():
	a_cost.append(a)

for b in b_num.split():
    b_cost.append(b)


cal_box = []

for i in range(int(M)):
    x, y, c = number[i].split()
        
    cal = int(a_cost[int(x)-1]) + int(b_cost[int(y)-1]) - int(c)
    cal_box.append(cal)

cal_box.append(int(min(a_cost)) + int(min(b_cost)))

print(int(min(cal_box)))

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

for k in range(M):
  x = dis[k][0] - 1
  y = dis[k][1] - 1
  c = dis[k][2]
  discount = a[x] + b[y] - c
  total.append(discount)
  
  
print(min(total))

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):
  x = a[c[i][0]-1] + b[c[i][1]-1] - c[i][2]
  if ans >= x:
    ans = x
print(ans)

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

min_a = min(a)
min_b = min(b)
min_std = min_a + min_b

work = []
cnt = 0
while True:
    cnt += 1
    work.append([int(i) for i in input().split()])
    
    if cnt == M:
        break
waribiki_list = []
for xyc in work:
    x, y ,c = xyc[0], xyc[1], xyc[2]
    
    waribiki_list.append(a[x-1] + b[y-1] - c)


if min_std > min(waribiki_list):
    print(min(waribiki_list))
else:
    print(min_std)

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

PA = list(map(int, input().split()))
PB = 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())

total = [0] * M





for k in range(M):
        
        total[k] = (PA[x[k]-1] + PB[y[k]-1]) - c[k]


ntotal = min(PA) + min(PB)

ytotal = min(total)

if ntotal > ytotal:
        print(ytotal)
else:
        print(ntotal)

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 = [int(i) for i in input().split()]
b = [int(i) for i 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)

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



 
cost = 10**25
for i in range (M):
    reizouko = x[i]-1
    densirenge = y[i]-1
    nedan = ((a[reizouko] + b[densirenge]) - c[i])
    
    if nedan <= cost:
        cost = nedan

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

Solution (Python):

from collections import Counter
def inputlist(): return [int(i) for i in input().split()]

A,B,M = inputlist()
a = inputlist()
b = inputlist()
ma = sorted(a)[0]
mb = sorted(b)[0]
mc = ma+mb
for i in range(M):
    x,y,c = inputlist()
    x -=1
    y -=1
    mc = min(mc,a[x]+b[y]-c)
print(mc)

Solution (Python):

from collections import Counter
def inputlist(): return [int(i) for i in input().split()]

A,B,M = inputlist()
a = inputlist()
b = inputlist()
ma = sorted(a)[0]
mb = sorted(b)[0]
mc = ma+mb
for i in range(M):
    x,y,c = inputlist()
    x -=1
    y -=1
    mc = min(mc,a[x]+b[y]-c)
print(mc)

Solution (Python):

from sys import setrecursionlimit
setrecursionlimit(10**6)
from collections import Counter
def inputlist(): return [int(i) for i in input().split()]

A,B,M = inputlist()
a = inputlist()
b = inputlist()
ma = sorted(a)[0]
mb = sorted(b)[0]
mc = ma+mb
for i in range(M):
    x,y,c = inputlist()
    x -=1
    y -=1
    mc = min(mc,a[x]+b[y]-c)
print(mc)

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)]
tmp = min(A) + min(B)
tmp1 = 100000000
for i in range(m):
    aa = xyc[i][0] - 1
    bb = xyc[i][1] - 1
    tmp1 = min(A[aa] + B[bb] - xyc[i][2], tmp1)

print(min(tmp, tmp1))

Solution (Python):
import copy
A,B,M = (int(x) for x in input().split())
a = list()
b = list()
x = list()
y = list()
c = list()
for j in input().split():
    a.append(int(j))

for j in input().split():
    b.append(int(j))
    
for i in range(M):
    tx,ty,tc = (int(j) for j in input().split())
    x.append(int(tx))
    y.append(int(ty))
    c.append(int(tc))

pat=0
mini = 200000
ca = copy.copy(a)
cb = copy.copy(b)
a.sort()
b.sort()

mini = a[0] + b[0]






for i in range(M):
    pat = ca[x[i]-1] + cb[y[i]-1] - c[i]
    if mini > pat:
        mini = pat

print(mini)

Solution (Python):




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

Solution (Python):
import sys
input = sys.stdin.readline
A, B, M = map(int, input().split())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
P = [list(map(int,input().split())) for i in range(M)]

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

print(ans)

Solution (Python):
import sys
def input(): return sys.stdin.readline().rstrip()
sys.setrecursionlimit(10 ** 7)

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

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

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

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):
    xi, yi, ci = map(int, input().split())
    ans = min(ans, a[xi - 1] + b[yi - 1] - ci)
print(ans)

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

amin = min(A)
bmin = min(B)
smin = amin + bmin

for i in range(m):
  x, y, c= map(int, input().split())
  th = smin + c
  apmin = A[x-1]
  if apmin > th:
    pass
  else:
    bpmin = B[y-1]
    spmin = apmin + bpmin -c
    if spmin < smin:
      smin = spmin
    else:
      pass
print(smin)

Solution (Python):

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


ans=min(al)+min(bl)

for i in range(m):
    x,y,c=map(int,input().split())
    ans=min(ans,al[x-1]+bl[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=[]
prices=[]
for i in range(M):
    x1,y1,c1=map(int,input().split())
    x.append(x1)
    y.append(y1)
    c.append(c1)
for i in range(M):
    prices.append(a[x[i]-1]+b[y[i]-1]-c[i])
prices.append(min(a)+min(b))
print(min(prices))

Solution (Python):
a,b,m = map(int,input().split())
a_list = list(map(int,input().split()))
b_list = list(map(int,input().split()))
discount_list = [list(map(int,input().split())) for _ in range(m)]

min_price = min(a_list) + min(b_list)

for discount in discount_list:
    min_price = min(min_price,a_list[discount[0]-1]+b_list[discount[1]-1]-discount[2])

print(min_price)

Solution (Python):
import cmath
import sys

INF=10**18
MOD=10**9+7
MAX=10**5+7



def main():
  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
    ans=min(ans, a[x]+b[y]-c)
  
  print(ans)
  
  
if __name__=='__main__':
    main()

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

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

Solution (Python):
a,b,m = [int(i) for i in input().split()]

al = [int(i) for i in input().split()]
bl = [int(i) for i in input().split()]

ans = min(al) + min(bl)

for i in range(m):
    ai,bi,ci = [int(i) for i in input().split()]
    ans = min(ans,al[ai-1] + bl[bi-1] - ci)
    
print(ans)

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()]
x, y, c = [[], [], []]
for i in range(M):
    inp = input().split()
    x.append(int(inp[0]))
    y.append(int(inp[1]))
    c.append(int(inp[2]))
mi = min(a) + min(b)
for i in range(M):
    waribiki = a[x[i]-1] + b[y[i]-1] - c[i]
    if waribiki < mi:
        mi = waribiki
print(mi)

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

a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))

min_price = min(a_list) + min(b_list)
for _ in range(M):
  x, y, c = map(int, input().split())
  discount_price = a_list[x-1] + b_list[y-1] - c
  min_price = min(min_price, discount_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()))
l=[[int(i) for i in input().split()] for j in range(M)]
m=min(a)+min(b)
for x in l:
    m=min(m,a[x[0]-1]+b[x[1]-1]-x[2])
print(m)

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)
M_list = []
for m in range(M):
  M_list = list(map(int, input().split()))
  _ = A_list[M_list[0]-1] + B_list[M_list[1]-1] - M_list[2]
  ans = min(_,ans)


print(ans)

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

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

minc=min(a)+min(b)

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

  if cash<minc:
    minc=cash

print(minc)

Solution (Python):




def main():
    A, B, M = map(int, input().split())
    al = list(map(int, input().split()))
    bl = list(map(int, input().split()))
    disc = []
    for i in range(M):
        x, y, c = map(int, input().split())
        disc.append({"x": x, "y": y, "c": c})

    
    a_min = min(al)
    b_min = min(bl)
    ans = a_min + b_min

    
    for d in disc:
        c = al[d["x"] - 1] + bl[d["y"] - 1] - d["c"]
        ans = min(ans, c)

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):




def main():
    A, B, M = map(int, input().split())
    al = list(map(int, input().split()))
    bl = list(map(int, input().split()))
    disc = []
    for i in range(M):
        x, y, c = map(int, input().split())
        disc.append({"x": x, "y": y, "c": c})

    
    a_min = min(al)
    b_min = min(bl)
    ans = a_min + b_min

    
    for d in disc:
        c = al[d["x"] - 1] + bl[d["y"] - 1] - d["c"]
        ans = min(ans, c)

    print(ans)


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

Solution (Python):
def resolve():
    a, b, m = map(int,input().split())
    R = list(map(int, input().split()))
    M = list(map(int, input().split()))
    X = [list(map(int, input().split())) for i in range(m)]

    ans = min(R) + min(M)
    for i in range(m):
        ans = min(ans, R[X[i][0]-1]+M[X[i][1]-1]-X[i][2])
    print(ans)

if __name__ == '__main__':
    resolve()

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()]
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())
price_A=list(map(int,input().split()))
price_B=list(map(int,input().split()))
coupon=[]
for _ in range(m):
  coupon.append(list(map(int,input().split())))
ans=min(price_A)+min(price_B)
for i in range(m):
  deprice=price_A[coupon[i][0]-1]+price_B[coupon[i][1]-1]-coupon[i][2]
  if deprice < ans:
    ans = deprice
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)]
mina = min(a)
minb = min(b)
ans = mina+minb
for i in range(M):
    if ans > a[C[i][0]-1] + b[C[i][1]-1] - C[i][2]:
        ans = a[C[i][0]-1] + b[C[i][1]-1] - C[i][2]
print(ans)

Solution (Python):
A, B, M = [int(x) for x in input().split(" ")]
As = list([int(x) for x in input().split(" ")])
Bs = list([int(x) for x in input().split(" ")])


minimumValue = 999999999
for i in range(M):
    x, y, c = [int(x) for x in input().split(" ")]
    x -= 1
    y -= 1
    minimumValue = min(minimumValue, As[x] + Bs[y] - c)

As.sort()
Bs.sort()

minimumValue = min(minimumValue, As[0] + Bs[0])
print(minimumValue)

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())
	q=a[x-1]+b[y-1]-c
	if q<=p:
		p=q
print(p)

Solution (Python):
def inp():
    return input()
def iinp():
    return int(input())
def inps():
    return input().split()
def miinps():
    return map(int,input().split())
def linps():
    return list(input().split())
def lmiinps():
    return list(map(int,input().split()))
def lmiinpsf(n):
    return [list(map(int,input().split()))for _ in range(n)]

A,B,M = miinps()
a = lmiinps()
b = lmiinps()
x = lmiinpsf(M)

mi = 10 ** 10

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

mi = min(mi,min(a)+min(b))

print(mi)

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

ans = min(A)+min(B)

for i in range(M):
    if A[xyc[i][0]-1]+B[xyc[i][1]-1]-xyc[i][2] < ans:
        ans = A[xyc[i][0]-1]+B[xyc[i][1]-1]-xyc[i][2]

print(ans)

Solution (Python):
def main():

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

    a_list = list(map(int, input().split()))

    b_list = list(map(int, input().split()))

    min_pair = a_list[a_list.index(min(a_list))] + b_list[b_list.index(min(b_list))]

    m_list = []
    for i in range(m):
        x,y,c = map(int, input().split())
        if a_list[x-1]+b_list[y-1]-c <= min_pair:
            min_pair = a_list[x-1]+b_list[y-1]-c

    print(min_pair)


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

from fractions import gcd
import math

from math import factorial as f

from math import ceil,floor,sqrt


import bisect
import re
import heapq


from copy import deepcopy
import itertools

from sys import exit

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

yes = "Yes"
no = "No"

def main():
    a,b,m = mi()
    alist = li()
    blist = li()
    ans = min(alist)+min(blist)
    for i in range(m):
        x,y,c = mi()
        ans = min(ans,alist[x-1]+blist[y-1]-c)
    print(ans)




main()

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

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

print(min(discount, cheap))

Solution (Python):
a, b, m = map(int, input().split())
A_lst = list(map(int, input().split()))
B_lst = list(map(int, input().split()))
dis_lst = [[0]*3 for _ in range(m)]
for i in range(m):
    x, y, c = map(int, input().split())
    dis_lst[i][0] = x - 1
    dis_lst[i][1] = y - 1
    dis_lst[i][2] = c

min_num = min(A_lst) + min(B_lst)
for dis in dis_lst:
    sum_num = A_lst[dis[0]] + B_lst[dis[1]] - dis[2]
    if sum_num < min_num:
        min_num = sum_num

print(min_num)

Solution (Python):
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))



A,B,M = LI()
a = LI()
b = LI()
x,y,c = LIR(M,3)

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

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

ans = min(lia) + min(lib)

for x,y,c in xyc:
    ans = min(ans, lia[x-1] + lib[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 = [int(i) for i in input().split()]

a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]

min_p = min(a) + min(b)

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

Solution (Python):
A, B, M = [int(x) for x in input().split()]
A_price_list = [int(x) for x in input().split()]
B_price_list = [int(x) for x in input().split()]

discount_list = []

for i in range(M):
    x, y, c = [int(x) for x in input().split()]
    discount_list.append([x-1, y-1, c])


amount = min(A_price_list) + min(B_price_list)

for x, y, c in discount_list:
    tmp_price = A_price_list[x] + B_price_list[y] - c
    amount = min(tmp_price, amount)

print(amount)

Solution (Python):
A,B,M = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
K = min(a)+min(b)
X = 10**9
for i in range(M):
    x,y,c = map(int,input().split())
    S = a[x-1]+b[y-1]-c
    if S<X:
        X = S
if X<K:
    print(X)
else:
    print(K)

Solution (Python):
A,B,M=map(int,input().split())
L_A=list(map(int,input().split()))
L_B=list(map(int,input().split()))
ans=min(L_A)+min(L_B)
for i in range(M):
	X,Y,Z=map(int,input().split())
	ans=min(ans,(L_A[X-1]+L_B[Y-1]-Z))
print(ans)

Solution (Python):
from sys import stdin

A, B, M = [int(x) for x in stdin.readline().rstrip().split()]
a = [int(x) for x in stdin.readline().rstrip().split()]
b = [int(x) for x in stdin.readline().rstrip().split()]
X = [[int(x) for x in stdin.readline().rstrip().split()] for _ in range(M)]

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

for x in X:
    L.append(a[x[0]-1] + b[x[1]-1] - x[2])
    
    
print(min(L))

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    aa,bb,m = LI()
    a = LI()
    b = LI()
    xyc = [LI() for _ in range(m)]
    r = min(a) + min(b)
    for x,y,c in xyc:
        t = a[x-1] + b[y-1] - c
        if r > t:
            r = t

    return r


print(main())

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

s = min(a)+min(b)

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

print(min(s,t))

Solution (Python):
lis = [int(x) for x in input().split()]
a = lis[0]
b = lis[1]
m = lis[2]
lis2 = []
A=[int(x) for x in input().split()]
B=[int(x) for x in input().split()]


for i in range(m):
    lis2.append([int(x) for x in input().split()])

min1 = min(A)+min(B)
cost = [A[lis2[x][0]-1] + B[lis2[x][1]-1] - lis2[x][2] for x in range(m)]
min2 = min(cost)

print(min([min1 , min2]))

Solution (Python):
def main():
    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)


if __name__ == "__main__":
    main()

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

wk = -1
for i in range(m):
    x, y, c = map(int, input().split())
    if wk == -1:
        wk = li_a[x - 1] + li_b[y - 1] - c
    else:
        wk = min(wk,li_a[x - 1] + li_b[y - 1] - c)
answer = min(wk,min(li_a) + min(li_b))
print(answer)

Solution (Python):
numA, numB, numCoupon = map(int, input().split(' '))
priceA = list(map(int, input().split(' ')))
priceB = list(map(int, input().split(' ')))


bestPrice = min(priceA) + min(priceB)

for n in range(numCoupon):
  
  typeA, typeB, discount = map(int, input().split(' '))
  
  currentPrice = priceA[typeA-1] + priceB[typeB-1] - discount
  
  if currentPrice < bestPrice:
    bestPrice = currentPrice

print(bestPrice)

Solution (Python):
p,q,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
z = [100000, 100000 ,200000]
for i in range(p):
    if(z[0] > A[i]):
        z[0] = A[i]
for i in range(q):
    if(z[1] > B[i]):
        z[1] = B[i]
for i in range(m):
    x[i],y[i],c[i] = map(int, input().split())
    if(A[x[i]-1] + B[y[i]-1] - c[i] < z[2]):
        z[2] = A[x[i]-1] + B[y[i]-1] - c[i]
print(min(z[0]+z[1], z[2]))

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()))
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()))
l = [input().split() for i in range(m)]
ans = min(a) + min(b)

for i in range(m):
    ai = a[int(l[i][0]) - 1]
    bi = b[int(l[i][1]) - 1]
    ci = int(l[i][2])
    nc = ai + bi - ci
    ans = min(ans, nc)
print(ans)

Solution (Python):
def solve(A, B, M, a, b, x, y, c):
    best = min(a) + min(b)
    for i in range(M):
        best = min(best, a[x[i]-1] + b[y[i]-1] - c[i])
    return best

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())
print(solve(A, B, M, a, b, x, y, c))

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

ans1=min(ap)+min(bp)
ans=[ans1]
for i in range(m):
    ai,bj,d=map(int,input().split())
    ans2=ap[ai-1]+bp[bj-1]-d
    ans.append(ans2)
    
print(min(ans))

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

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

ans = []
for x,y,c in xyc:
    ans.append(a1[x-1] + b1[y-1] - c)
ans.append(min(a1) + min(b1))
print(min(ans))

Solution (Python):
S = input().split()


A = int(S[0])

B = int(S[1])

M = int(S[2])



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


for i in range(M):
    m = list(map(int,input().split()))
    amount = a[m[0]-1] + b[m[1]-1] - m[2]

    if total_mini > amount:
        total_mini = amount


print(total_mini)

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):
listA=[]

while True:
    try:
        listA.append(list(map(int,input().split())))

    except:
        break;
        

money = min(listA[1]) + min(listA[2]) 
wari = 100000000

for k in range(listA[0][2]):
    a = listA[k+3][0]
    b = listA[k+3][1]
    if wari > listA[1][a-1] + listA[2][b-1] - listA[k+3][2]:
        wari = listA[1][a-1] + listA[2][b-1] - listA[k+3][2]

if money <= wari:
    print(money)
        
else:
    print(wari)