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

a_l_s = sorted(a_l)
b_l_s = sorted(b_l)

min_price = (10 ** 5) * 3
for i in range(m):
    price = a_l[x_y_c[i][0] - 1] + b_l[x_y_c[i][1] - 1] - x_y_c[i][2]
    if price < min_price:
        min_price = price

tmp = a_l_s[0] + b_l_s[0]
if tmp < min_price:
    print(tmp)
else:
    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

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

print(ans)

Solution (Python):

input_line = input()
Line = input_line.split()
Line = [int(s) for s in Line]

input_line = input()
reizou = input_line.split()
reizou = [int(s) for s in reizou]



input_line = input()
densi = input_line.split()
densi = [int(s) for s in densi]



hutuu_min = min(reizou)+min(densi)


for i in range(Line[2]):
    input_line = input()
    ticket = input_line.split()
    ticket = [int(s) for s in ticket]
    
    ticket_min = reizou[ticket[0]-1]+densi[ticket[1]-1]-ticket[2]
    
    if ticket_min < hutuu_min:
        hutuu_min = ticket_min

print(hutuu_min)

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 _ in range(M):
    x,y,c = map(int,input().split())
    p.append(a[x-1]+b[y-1]-c)

print(min(p))

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

r=min(a)
d=min(b)

W=[]
for i in C:
    w=a[i[0]-1]+b[i[1]-1]-i[2]
    W.append(w)

print(min(r+d,min(W)))

Solution (Python):
ABM = list(map(int, input().split()))
price_A = list(map(int, input().split()))
price_B = list(map(int, input().split()))

waribiki = []
for i in range(ABM[2]):
    waribiki.append(list(map(int, input().split())))

result = []
for i in waribiki:
    result.append(price_A[i[0] - 1] + price_B[i[1] - 1] - i[2])

result.append(min(price_A) + min(price_B))

print(min(result))

Solution (Python):
(A, B, M) = [int(k) for k in input().split(' ')]
a = [int(k) for k in input().split(' ')]
b = [int(k) for k in input().split(' ')]
coupons = []
for i in range(M):
  coupons.append([int(k) for k in input().split(' ')])

price = min(a) + min(b)
for c in coupons:
  pr = a[c[0]- 1] + b[c[1]- 1] - c[2]
  if pr < price:
    price = pr

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

Solution (Python):
a, b, m = list(map(int, input().split()))
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
sum_list = []

min_sum = min(a_list) + min(b_list)


for i in range(m):
    x, y, c = list(map(int, input().split()))
    sum = a_list[x - 1] + b_list[y - 1] - c
    sum_list.append(sum)

print(min(min(sum_list), min_sum))

Solution (Python):
A, B, M = map(int, input().split())
lenzi=list(map(int,input().split()))
zouko=list(map(int,input().split()))
mlenzi=100000
mzouko=100000
mPrice = 200000
for i in range(A):
  if lenzi[i]<mlenzi:
    for j in range(B):
      if zouko[j]<mzouko:
        if lenzi[i]+zouko[j]<mPrice:
          mPrice=lenzi[i]+zouko[j]
        mzouko=zouko[j]
    mlenzi=lenzi[i]
for i in range(M):
  x, y, c = map(int, input().split())
  if lenzi[x-1]+zouko[y-1]-c<mPrice:
    mPrice=lenzi[x-1]+zouko[y-1]-c
print(mPrice)

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)]
pay = 0
min_pay = 0
for i in range(M):
  pay = a[xyc[i][0]-1] + b[xyc[i][1]-1] - xyc[i][2]
  if i == 0:
    min_pay = pay
  min_pay = min(min_pay,pay)
min_pay = min(min_pay,min(a)+min(b))
print(min_pay)

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

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

min_price = min(a) + min(b)

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

print(min_price)

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 _ in range(M):
    x, y, c = map(int, input().split())
    S = a_list[x - 1] + b_list[y - 1] - c

    if ans > S:
        ans = S

print(ans)

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

aa = list(map(int, input().split()))
bb = list(map(int, input().split()))



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



ma = min(aa)
mb = min(bb)
ans = ma+mb



for i in range(m):
    sum = aa[xyc[i][0] -1] + bb[xyc[i][1] -1] - xyc[i][2]
    
    if ans > sum:
        ans = sum

print(ans)

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

waribiki=[]

for _ in range(M):
    waribiki.append(list(map(int,input().split())))

MIN=min(a)+min(b)

for wari in waribiki:
    x=wari[0]-1
    y=wari[1]-1
    value=wari[2]
    total=a[x]+b[y]-value
    if(total < MIN):
        MIN=total

print(MIN)

Solution (Python):
input1 = list(map(int, (input().split())))

a = input1[0]
b = input1[1]
m = input1[2]

alist = list(map(int, (input().split())))
blist = list(map(int, (input().split())))

mlist = [[]] * m


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


amin = min(alist)
bmin = min(blist)

res = amin + bmin

for e in mlist:
    x = e[0] - 1
    y = e[1] - 1
    c = e[2]
    if alist[x] + blist[y] - c < res:
        res = alist[x] + blist[y] - c

print(res)

Solution (Python):
A, B, M = map(int, input().split())
fridge_prices = list(map(int,input().split()))
wave_prices = list(map(int,input().split()))
coupons =[list(map(int,input().split()))for _ in range(M)]

fridge_min = min(fridge_prices)
wave_min = min(wave_prices)

f_min_index = fridge_prices.index(fridge_min)
w_min_index = wave_prices.index(wave_min)

no_coupon_min = fridge_prices[f_min_index] + wave_prices[w_min_index]

min_price = no_coupon_min

for i in range(M):
  tp = fridge_prices[coupons[i][0] - 1] + wave_prices[coupons[i][1] - 1]  - coupons[i][2]
  if min_price > tp:
    min_price = tp
print(min_price)

Solution (Python):


a_size, b_size, m_size = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
m = []
for i in range(m_size):
    m.append(list(map(int, input().split())))


min_sum = min(a) + min(b)


for i in range(m_size):
    s = a[m[i][0]-1] + b[m[i][1]-1] - m[i][2]
    if min_sum > s:
        min_sum = s

print(min_sum)

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


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


if d>f:
    d=f
print(d)

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

refredge = list(map(int, input().split()))
microwave = list(map(int, input().split()))

costs = []
for i in range(M):
    dis = list(map(int, input().split()))
    cos = (refredge[dis[0]-1] + microwave[dis[1]-1] - dis[2])
    costs.append(cos)
abcost = min(refredge) + min(microwave)
print(min(min(costs), abcost))

Solution (Python):



def solve(*args: str) -> str:
    a, b, m = map(int, args[0].split())
    A = list(map(int, args[1].split()))
    B = list(map(int, args[2].split()))

    XYC = {}
    for x, y, c in map(str.split, args[3:]):
        key = (int(x)-1, int(y)-1)
        XYC[key] = max(XYC.get(key, 0), int(c))

    ret = min(A)+min(B)
    for (x, y), c in XYC.items():
        ret = min(ret, A[x]+B[y]-c)

    return str(ret)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))

Solution (Python):
A,B,M = map(int,input().split())
a = input().split()
b = input().split()
L = []
for i in range(M):
    l = input().split()
    L.insert(i,l)
sum_min = int(min(a)) + int(min(b))  

P = []
for i in range(M):
    p = int(a[int(L[i][0])-1]) + int(b[int(L[i][1])-1]) - int(L[i][2])
    P.append(p)
pmin = min(P)
    
if pmin < sum_min:
        ans = pmin
else:
    ans = sum_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()))


ans = min(A_list) + min(B_list)


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

print(ans)

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

Solution (Python):
As, Bs, Ms = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

bas = min(A) + min(B)

ans = bas
for i in range(Ms):
  a, b, c = map(int, input().split())
  if A[a-1]+B[b-1]-c < ans:
    ans = A[a-1]+B[b-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()))
disc = []
for i in range(M):
  disc.append(list(map(int,input().split())))
ans = min(a) + min(b)
for i in range(M):
  ans = min(a[disc[i][0]-1] + b[disc[i][1]-1] - disc[i][2], ans)     
    
print(ans)

Solution (Python):
A,B,M = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
x =[]
y = []
c = []
wari = []
for i in range (M):
    s = list(map(int, input().split()))
    x.append(s[0])
    y.append(s[1])
    c.append(s[2])
for j in range(M):
    d = a[x[j]-1] + b[y[j]-1] - c[j]
    wari.append(d)
f1 = min(a) + min(b)
f2 = min(wari)
if f1 >= f2:
    print(f2)
else:
    print(f1)

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




total = 10**5+10**5


for i in range(m):
    x,y,c=map(int,input().split())
    
    D = (A[x-1] + B[y-1] - c)
    if total > D:
        total = D
    
A.sort()
B.sort()
if total > (A[0] + B[0]):
    total = (A[0] + B[0])
print(total)

Solution (Python):
abm=(input().split(" "))
al1=list(map(int,input().split(" ")))
bl1=list(map(int,input().split(" ")))


minp=min(al1)+min(bl1)


for n in range(0,int(abm[2])):
    a,b,c = map(int,input().split())
    ci=int(al1[a-1])+int(bl1[b-1])-int(c)
    if minp>ci:
        minp=ci

print(minp)

Solution (Python):
A,B,M = map(int,input().split())
Frigo = list(map(int,input().split()))
Micro = list(map(int,input().split()))
Discount = []
for i in range(M):
  x,y,c = map(int,input().split())
  Discount.append(Frigo[x-1]+Micro[y-1]-c)
Best_discount = min(Discount)
print(min((min(Frigo)+min(Micro)),Best_discount))

Solution (Python):
A, B, M = map(int, input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
X = 0
Y = 0
C = 0
Sum = min(a) + min(b)
Min = 10**8

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

if Sum < Min:
    print(Sum)
    exit()
print(Min)

Solution (Python):
a, b, m = map(int,raw_input().split())
dr = map(int,raw_input().split())
wa = map(int,raw_input().split())
xyc = [map(int,raw_input().split()) for i in range(m)]
low = 200001

for i in range(m):
    f = xyc[i][0] - 1
    d = xyc[i][1] - 1
    if low >= dr[f]+wa[d]-xyc[i][2]:
        low = dr[f]+wa[d]-xyc[i][2]

dr.sort()
wa.sort()

if low >= (dr[0] + wa[0]):
    print (dr[0] + wa[0])
else:
    print low

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 = 10 ** 5 + 10 ** 5
for x, y, c in xyc:
  if a[x - 1] + b[y - 1] - c < ans:
    ans = a[x - 1] + b[y - 1] - c
m_price = min(a) + min(b)

print(ans if ans < m_price else m_price)

Solution (Python):
a, b, m = map(int, input().split())
arr = list(map(int, input().split()))
brr = list(map(int, input().split()))
ans = min(arr) + min(brr)
for _ in range(m):
    x, y, c = map(int, input().split())
    ans = min(ans, arr[x - 1] + brr[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()))
minA = a[0]
for reizou in a[1:]:
    if reizou < minA:
        minA = reizou
minB = b[0]
for renzi in b:
    if renzi < minB:
        minB = renzi
kakaku = minA + minB
for i in range(M):
    x,y,c = map(int,input().split())
    sumKakaku = a[x-1] + b[y-1] - c
    if sumKakaku < kakaku:
        kakaku = sumKakaku

print(kakaku)

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

a=[]
b=[]

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

mina=min(a)
minb=min(b)

mi = mina + minb

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

print(mi)

Solution (Python):
import sys

A, B, M = [int(x) for x in sys.stdin.readline().strip().split(" ")]
list_a = [int(x) for x in sys.stdin.readline().strip().split(" ")]
list_b = [int(x) for x in sys.stdin.readline().strip().split(" ")]
min_a = sorted(list_a)[0]
min_b = sorted(list_b)[0]

dict_c = {}
idx = []
for i in range(M):
    x, y, c = [int(x) for x in sys.stdin.readline().strip().split(" ")]
    if x not in dict_c:
        dict_c[x] = {}
    if c > dict_c[x].get(y, 0):
        dict_c[x][y] = c

    idx.append(tuple([x, y]))

s = min_a + min_b
for (x, y) in idx:
    t = list_a[x - 1] + list_b[y - 1] - dict_c[x][y]
    if t < s:
        s = t
print(s)

Solution (Python):
A, B, M = map(int, input().split())
a_ = list(map(int,input().split()))
b_ = list(map(int,input().split()))
price = []

for i in range(0, M):
    c = list(map(int, input().split()))
    price.append(a_[c[0]- 1]+b_[c[1]- 1]-c[2])

price.append(min(a_)+min(b_))
print(min(price))

Solution (Python):
import sys
readline = sys.stdin.readline
a, b, m = map(int, readline().split())
a = list(map(int, readline().split()))
b = list(map(int, readline().split()))
xyc = [list(map(int, readline().split())) for _ in range(m)]

ans = min(a) + min(b)
for x, y, c in xyc:
    price = a[x-1] + b[y-1] - c
    if price < ans:
        ans = price
print(ans)

Solution (Python):
import sys
lines = sys.stdin.readlines()
line1 = lines.pop(0).split(' ')
lineA = lines.pop(0).split(' ')
lineB = lines.pop(0).split(' ')

minP = int(min(lineA)) + int(min(lineB))


A = int(line1[0])

B = int(line1[1])

M = int(line1[2])


for i in range(M):
  line = lines.pop(0).split(' ')
  ax = int(line[0])
  bx = int(line[1])
  cx = int(line[2]) if len(line) == 3 else 0
  
  
  
  price = int(lineA[ax-1]) + int(lineB[bx-1]) - cx
  
  if minP > price:
    minP = price

print(minP)

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

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



x=[]
y=[]
m=[]

for i in range(M):
    kari=input().split(" ")
    x.append(int(kari[0]))
    y.append(int(kari[1]))
    m.append(int(kari[2]))

waribiki=[]

for i in range(M):
    waribiki.append(a[x[i]-1]+b[y[i]-1]-m[i])

aa=min(waribiki)
bb=min(a)+min(b)

print(min(aa,bb))

Solution (Python):
A,B,M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
z = []
x = []
y = []
c = []
for i in range(M):
    z.append(list(map(int, input().split())))
    x.append(z[i][0])
    y.append(z[i][1])
    c.append(z[i][2])

mi = min(a) + min(b)

for i in range(M):
    if a[x[i]-1] + b[y[i]-1] - c[i] < mi:
        mi = a[x[i]-1] + b[y[i]-1] - c[i]

print(mi)

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

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

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


tmp_min = min(a)+min(b)

for i in range(len(xyc)):
	tmp = a[xyc[i][0]-1]+b[xyc[i][1]-1]-xyc[i][2]
	if tmp<tmp_min:
		tmp_min=tmp
print(tmp_min)

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

Solution (Python):
refN, renN, disN = map(int, input().split())
 
ref = list(map(int,input().split()))
ren = list(map(int,input().split()))
 
dis = [input().split() for _ in range(disN)]
 
minCost = 0
wake = 0
 
for kk in range(disN):
    cost = ref[int(dis[kk][0])-1] + ren[int(dis[kk][1])-1] - int(dis[kk][2])
    if wake == 0 or cost < minCost:
        wake = 1
        minCost = cost
 
ref.sort()
ren.sort()
 
cost = ren[0] + ref[0]
if cost < minCost:
    minCost = cost
 
print(minCost)

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

Solution (Python):
A,B,M = map(int,input().rstrip().split())
a = list(map(int, input().rstrip().split()))
b = list(map(int, input().rstrip().split()))
x = [list(map(int,input().rstrip().split())) for _ in range(M)]
Low_price = min(a) + min(b)
disc_prices = []
for i in range(M):
	disc_prices.append(a[x[i][0]-1] + b[x[i][1]-1] - x[i][2])
if Low_price <= min(disc_prices):
	print(Low_price)
else:
  	print(min(disc_prices))

Solution (Python):
A, B, M = map(int, input().split())
lis_a = list(map(int, input().split()))
lis_b = list(map(int, input().split()))
lis_m = [list(map(int, input().split())) for m in range(M)]


dp_min = [2*10**5]*len(lis_m)
dp_min[0] = lis_a[(lis_m[0][0]-1)] + lis_b[(lis_m[0][1]-1)] - lis_m[0][2]
for m in range(1, len(lis_m)):
    ind_a = lis_m[m][0]-1
    ind_b = lis_m[m][1]-1
    c = lis_m[m][2]
    dp_min[m] = min(dp_min[m-1], (lis_a[ind_a] + lis_b[ind_b] - c))

p_not_coupon = min(lis_a)+min(lis_b)
ans = min(dp_min[-1], p_not_coupon)
print(ans)

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

mylist=[]
largelist=[]
Alist=list(map(int,input().split()))
Blist=list(map(int,input().split()))
pricelist=[]

for i in range(M):
    mylist=list(map(int,input().split()))
    largelist.append(mylist)
    



no_wari=min(Alist)+min(Blist)
pricelist.append(no_wari)


for i in range(M):
    now_a=largelist[i][0]
    now_b=largelist[i][1]
    now_c=largelist[i][2]
    
    pricelist.append(Alist[now_a-1]+Blist[now_b-1]-now_c)
    
print(min(pricelist))

Solution (Python):
f=input().split(" ")
a,b,m=[int(f[i]) for i in range(3)]
coup=[]
As=[]
Bs=[]
f=input().split(" ")
for each in f:
    As.append(int(each))

f=input().split(" ")
for each in f:
    Bs.append(int(each))

for i in range(m):
    f=input().split(" ")
    vac=[]
    for each in f:
        vac.append(int(each))
    coup.append(vac)
        
price=min(As)+min(Bs)
for each in coup:
    price_c=As[each[0]-1]+Bs[each[1]-1]-each[2]
    if price_c<price:
        price=price_c
print(price)

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

Solution (Python):
A,B,M = map(int,input().split())
rei = list(map(int,input().split()))
ren = list(map(int,input().split()))
rrw = []
for i in range(M):
    rrw.append(list(map(int,input().split())))
saiyasu = min(rei) + min(ren)
for j in range(M):
    onedan = rei[(rrw[j][0])-1] + ren[rrw[j][1]-1] - rrw[j][2]
    if onedan < saiyasu:
        saiyasu = onedan

print(saiyasu)

Solution (Python):
A, B, M = map(int, input().split(' '))
a = list(map(int, input().split(' ')))
b = list(map(int, input().split(' ')))
discountDic = {}
for i in range(M):
    x, y, c = map(int, input().split(' '))
    key = (x-1)*B+(y-1)
    if key not in discountDic or discountDic[key] > a[x-1] + b[y-1] - c:
        discountDic[key] = a[x-1] + b[y-1] - c
discount_min_price = min(discountDic.values())
all_low_price = min(a) + min(b)
if discount_min_price < all_low_price:
    print(discount_min_price)
else:
    print(all_low_price)

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

Solution (Python):
import numpy as np


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

order = np.ones([M,3])

for i in range(M):
    order[i,0],order[i,1],order[i,2] = [int(j) for j in input().split()]
    
dis_pri = float('inf')

for i in range(M):
    if dis_pri > (a[int(order[i,0])-1] + b[int(order[i,1])-1] - order[i,2]):
        dis_pri = int(a[int(order[i,0])-1] + b[int(order[i,1])-1] - order[i,2])
        


        
sim_pri = int(min(a) + min(b))
ans = min(sim_pri, dis_pri)
              
print(ans)

Solution (Python):
a,b,m=map(int,input().split(" "))
freezers=list(map(int,input().split(" ")))
microwaves=list(map(int,input().split(" ")))
cooponList=[list(map(int,input().split(" "))) for i in range(m)]

minimum=min(freezers)+min(microwaves)
cost=0
for i in range(m):
    cost=freezers[cooponList[i][0]-1]+microwaves[cooponList[i][1]-1]-cooponList[i][2]
    if cost<minimum:
        minimum=cost

print(minimum)

Solution (Python):
an,bn,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):
  xt,yt,ct = map(int,input().split())
  x.append(xt)
  y.append(yt)
  c.append(ct)

'''
print('{} {} {}'.format(an,bn,m))
print(a)
print(b)
print(x)
print(y)
print(c)
'''


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


ans= 0
tmp =0

ans = min(a) + min(b)


for i in range(M):
    if a[x[i]-1] + b[y[i]-1] - c[i] < ans:
        ans = a[x[i]-1] + b[y[i]-1] - c[i]

print(ans)

Solution (Python):
import sys

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

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

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

cheapest = 2000001

for i in range(m):
  cou = list(map(int, input().split()))
  tmp = ref[cou[0] - 1] + mic[cou[1] - 1] - cou[2]
  if(cheapest > tmp):
    cheapest = tmp

refMin = min(ref)
micMin = min(mic)
if(cheapest > refMin + micMin):
  cheapest = refMin + micMin

print(cheapest)

Solution (Python):
A,B,M=list(map(int,input().split()))
a=list(map(int,input().split()))
b=list(map(int,input().split()))
x=[]
y=[]
c=[]

for i in range(M):
    x1,y1,c1=list(map(int,input().split()))
    x.append(x1)
    y.append(y1)
    c.append(c1)

sum=min(a)+min(b)
for i in range(0,M):
    sum1=a[x[i]-1]+b[y[i]-1]-c[i]
    if sum>sum1:
        sum=sum1

print(sum)

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

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

a, b, m = MAP()
A = LIST()
B = LIST()
A_s = sorted(A)
B_s = sorted(B)


L = [LIST() for i in range(m)]

ans = A_s[0] + B_s[0]
for x, y, c in L:
    
    v = A[x-1] + B[y-1] - c
    if ans > v:
        ans = v
print(ans)

Solution (Python):
a, b, m = map(int, input().split())
a_arr = list(map(int, input().split()))
b_arr = list(map(int, input().split()))
waribiki = []

for i in range(m):
    waribiki.append(list(map(int, input().split())))

yen = min(a_arr) + min(b_arr)
for i in range(m):
    yen = min(yen, a_arr[(waribiki[i][0] - 1)] + b_arr[(waribiki[i][1] - 1)] - waribiki[i][2])

print(yen)

Solution (Python):
import sys
from heapq import heappush, heappop, heapify
from collections import defaultdict

A,B,M=map(int, sys.stdin.readline().split())
a=map(int, sys.stdin.readline().split())
b=map(int, sys.stdin.readline().split())

ans=float("inf")
for _ in range(M):
    x,y,c=map(int, sys.stdin.readline().split())
    ans=min(ans,a[x-1]+b[y-1]-c)

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

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

sums = []
for i in range(m):
    m_list = list(map(int, input().split()))
    sum = a_list[m_list[0]-1] + b_list[m_list[1]-1] - m_list[2]
    sums.append(sum)

mins = min(a_list) + min(b_list)
sum_min = min(sums)
print(min(sum_min, mins))

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

ans = min(a) + min(b)


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

print(ans)

Solution (Python):
from operator import itemgetter

A, B, M = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
d = [[int(i) for i in input().split()] for _ in range(M)]

ans = float("inf")
for i in range(M):
	ans = min(ans, A[d[i][0]-1] + B[d[i][1]-1] - d[i][2])

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

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

List = [min(aList) + min(bList)]

for _ in range(0, m) :
    x, y, c = map(int, input().split())
    List += [aList[x-1] + bList[y-1] - c]

print(min(List))

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

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

s=list(map(int,input().split()))
for i in range(A):
  a.append([s[i],i])
a.sort()
t=list(map(int,input().split()))
for i in range(B):
  b.append([t[i],i])
b.sort()
ans=a[0][0]+b[0][0]

for i in range(m):
  p,q,r=map(int,input().split())
  ans=min(ans,s[p-1]+t[q-1]-r)

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):
    xx, yy, cc = map(int, input().split())
    x.append(xx)
    y.append(yy)
    c.append(cc)
    
l = []
l.append(min(a)+min(b))

for i in range(M):
    ans = a[x[i]-1] + b[y[i]-1] - c[i]
    l.append(ans)
    
print(min(l))

Solution (Python):



def main():
  A, B, M = map(int, input().split())
  reizoko = list(map(int, input().split()))
  renji = 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())
  waribiki = []
  ans = []
  ans.append((min(reizoko)) + (min(renji)))
  for i in range(M):
    waribiki.append(reizoko[x[i]-1] + renji[y[i]-1] - c[i])
  ans.append(min(waribiki))
  print(min(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 = 200000

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)