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

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

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

tickets = np.zeros((M ,3))
for i in range(M):
    tickets[i,:] =  list(map(int, input().split()))
x1 = int(tickets[0,0])
y1 = int(tickets[0,1])
c1 = int(tickets[0,2])
min_ticket = valueA[x1-1] + valueB[y1-1] - c1
if M != 1:
    for i in range(1,M):
        xi = int(tickets[i,0])
        yi = int(tickets[i,1])
        ci = int(tickets[i,2])
        value = valueA[xi-1] + valueB[yi-1] - ci
        if value < min_ticket:
            min_ticket = value
"""
min_itself = valueA[0] + valueB[0]

for i in range(A):
    for j in range(B):
        value = valueA[i] + valueB[j]
        if value < min_itself:
            min_itself = value
min_all = min(min_itself, min_ticket)
"""
minA = min(valueA)
minB = min(valueB)
min_itself = minA + minB
min_all = min(min_itself, min_ticket)
print(min_all)

Solution (Python):
INF = 10 ** 18

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

answer = INF
for x, y, c in xyc:
    answer = min(answer, a[x - 1] + b[y - 1] - c)
answer = min(answer, min(a) + min(b))

print(answer)

Solution (Python):
import sys

counts = list(map(int,input().split()))
colors = list(map(int,input().split()))
hots = list(map(int,input().split()))

ticketCount = counts[2]

minPrice = sys.maxsize

for i in range(ticketCount):
  values = input().split()
  x = int(values[0])
  y = int(values[1])
  dissPrice = int(values[2])
  colorPrice = colors[x-1]
  hotsPrice = hots[y-1]
  validPrice =  colorPrice + hotsPrice - dissPrice
  if minPrice > validPrice:
    minPrice = validPrice

max_color = min(colors)
max_color_idx = colors.index(max_color)
max_hots = min(hots)
max_hots_idx = hots.index(max_hots)
validPrice = max_color + max_hots
if minPrice > validPrice:
  minPrice = validPrice
print(str(minPrice))

Solution (Python):

def main():
    A, B, M, *ABX = map(int, open(0).read().split())
    fridges, microwaves, X = ABX[:A], ABX[A : A + B], ABX[A + B :]
    with_tickets = min(
        fridges[x - 1] + microwaves[y - 1] - c for x, y, c in zip(*[iter(X)] * 3)
    )
    without_tickets = min(fridges) + min(microwaves)
    print(min(with_tickets, without_tickets))


if __name__ == "__main__":
    main()

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

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

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

a_min = min(a)
b_min = min(b)
ans = a_min + b_min

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

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

Solution (Python):
a,b,m= map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
l=[]
for i in range(m):
        l.append(list(map(int, input().split())))
sa=sorted(a)
sb=sorted(b)
ans=sa[0]+sb[0]
for i in range(m):
        sm= a[l[i][0]-1] + b[l[i][1]-1] - l[i][2]
        if ans > sm:
                ans=sm
print(ans)

Solution (Python):
na,nb,nm =  map(int, (input().split()))

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

mina = a[0]
minb = b[0]
for i in range(na):
    if a[i] < mina :
        mina = a[i]
for j in range(nb):
    if b[j] < minb :
        minb = b[j]
min = mina + minb


for k in range(nm):
    i,j,disc = map(int, input().split())
    if min > a[i-1]+b[j-1]-disc:
        min = a[i-1]+b[j-1]-disc

print(min)

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_price = list(map(int,input().split()))
b_price = list(map(int,input().split()))
coupon = []
for i  in range(m):
    coupon.append(list(map(int,input().split())))
    


def get_min(a_price, b_price, coupon):
    minprice= min(a_price)+min(b_price)
    for k in range(m):
        aindex  = coupon[k][0]-1
        bindex  = coupon[k][1]-1
        sale = coupon[k][2]
        price = a_price[aindex]+b_price[bindex]-sale
        if price < minprice:
            minprice = price
    return minprice

print(get_min(a_price, b_price, coupon))

Solution (Python):
a,b,m=map(int,input().split())
ai=list(map(int, input().split()))
bi=list(map(int, input().split()))
sm=[list(map(int, input().split())) for _ in range(m)]
k=min(ai)+min(bi)

for x in range(m):
    
    l=ai[sm[x][0]-1]+bi[sm[x][1]-1]-sm[x][2]
    k=min(k,l)

print(k)

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

for s,t,u in x:
    tmp=A[s-1]+B[t-1]-u
    ans=min(ans,tmp)
print(ans)

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

ans = min(ref) + min(ran)

for i in range(m):
  t = list(map(int,input().split()))
  p = t[0] 
  q = t[1]
  c = t[2]
  if (len(ref) >= p and len(ran) >= q):
    if ref[p - 1] + ran[q - 1] - c < ans:
      ans = ref[p - 1] + ran[q - 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()))

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

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


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

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())
    
cal_1=min(a)+min(b)
cal_2=[0]*M

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

if cal_1>=cal_3:
    print(cal_3)
else:
    print(cal_1)

Solution (Python):
_,a,b,*t=[list(map(int,i.split())) for i in open(0)]
n=min(a)+min(b)
for x,y,c in t:n=min(n,a[x-1]+b[y-1]-c)
print(n)

Solution (Python):
_,a,b,*t=[list(map(int,i.split())) for i in open(0)]
n=min(a)+min(b)
for x,y,c in t:n=min(n,a[x-1]+b[y-1]-c)
print(n)

Solution (Python):
_,a,b,*t = [list(map(int,i.split())) for i in open(0)]
n=min(a)+min(b)
for x,y,c in t:n=min(n,a[x-1]+b[y-1]-c)
print(n)

Solution (Python):
_,a,b,*t = [list(map(int,t.split())) for t in open(0)]
n=min(a)+min(b)
for x,y,c in t:
  n=min(n,a[x-1]+b[y-1]-c)
print(n)

Solution (Python):
_,a,b,*t = [list(map(int,i.split())) for i in open(0)]
n=min(a)+min(b)
for x,y,c in t:
  n=min(n,a[x-1]+b[y-1]-c)
print(n)

Solution (Python):
x = input().split()
A = int(x[0])
B = int(x[1])
M = int(x[2])
a = input().split()
b = input().split()

a = [int(l) for l in a]
b = [int(l) for l in b]

c = min(a) + min(b)

for i in range(M):
    z = input().split()
    c1 = a[int(z[0])-1] + b[int(z[1])-1] - int(z[2])
    if c > c1:
        c = c1

print(c)

Solution (Python):
_,a,b,*t=[list(map(int,t.split()))for t in open(0)];print(min([min(a)+min(b)]+[a[x-1]-c+b[y-1]for x,y,c in t]))

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

Solution (Python):
_,a,b,*t=[list(map(int,t.split()))for t in open(0)];print(min([min(a)+min(b)]+[a[x-1]-c+b[y-1]for x,y,c in t]))

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 _ in range(M):
    a, b, m = list(map(int, input().split()))
    ans = min(ans, al[a-1]+bl[b-1]-m)
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())
    t = A[x - 1] + B[y - 1] - c
    if t < ans:
        ans = t

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):
  i,j,c=map(int,input().split())
  i-=1; j-=1
  ans=min(ans,A[i]+B[j]-c)
print(ans)

Solution (Python):
A, B, M = map(int, input().split())
alist = list(map(int, input().split()))
blist = list(map(int, input().split()))
xyclist = [list(map(int, input().split())) for _ in range(M)]
am, bm = min(alist), min(blist)
ans = am + bm

for x, y, c in xyclist:
    ans = min(ans, alist[x-1]+blist[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
    ans = min(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()))
M = []
for _ in range(m):
  M.append(list(map(int,input().split())))
  
min_price = min(A) + min(B)
for s in M:
  price = A[s[0]-1] + B[s[1]-1] - s[2]
  if min_price > price:
    min_price = price
    
print(min_price)

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

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

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

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

a = list(map(int,input().split()))
b = list(map(int,input().split()))
list1 = [list(map(int,input().split())) for i in range(M)]

sum = min(a) + min(b)

for i in range(0, M):
    x = list1[i][0]
    y = list1[i][1]
    c = list1[i][2]
    num = a[x-1]+b[y-1]-c
    
    sum = min(sum, num)

print(sum)

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

al=[]
a=input().split()
for i in a:
    al.append(int(i))
bl = []
b=input().split()
for i in b:
    bl.append(int(i))

cl=[]
for i in range(M):
    l=[]
    c = input().split()
    for i in c:
        l.append(int(i))
    cl.append(l)
    
l=[]
for i in cl:
    a=0
    a=al[i[0]-1]+bl[i[1]-1]-i[2]
    l.append(a)

Min=min(al) + min(bl)
if min(l) < Min:
    print(min(l))
else:
    print(Min)

Solution (Python):
def main():
  import sys
  
  a, b, m = map(int, input().split())
  a = list(map(int, sys.stdin.readline().split()))
  b = list(map(int, sys.stdin.readline().split()))
  ans = min(a) + min(b)
  
  for _ in range(m):
    i, j, c = map(int, input().split())
    ans = min(ans, a[i-1]+b[j-1]-c)
  
  print(ans)
  
if __name__=='__main__':
  main()

Solution (Python):
a, b, m = map(int,raw_input().split())
al = map(int,raw_input().split())
bl = map(int,raw_input().split())
low = min(al)+min(bl)
x = [0] * m
y = [0] * m
c = [0] * m

for i in range(m):
    x[i],y[i],c[i] = map(int, raw_input().split())
    x[i] -= 1
    y[i] -= 1
 
for i in range(m):
    low = min(low,al[x[i]]+bl[y[i]]-c[i])

print low

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(tmp,ans)
print(ans)

Solution (Python):
r,p,m=range,print,min
n,a,b=[list(map(int,input().split()))for i in r(3)]
l=[]
for i in r(n[2]):
  x,y,z=map(int,input().split())
  l.append(a[x-1]+b[y-1]-z)
p(m([m(a)+m(b),m(l)]))

Solution (Python):



from sys import stdin


def calc_min_price(a_list, b_list,  pricedown_list):
    
    min_a = min(a_list)
    min_b = min(b_list)
    min_price = min_a + min_b

    
    for i, j, price in pricedown_list:
        min_price = min(min_price, a_list[i-1]+b_list[j-1]-price)

    return min_price



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


a_list = [int(x) for x in stdin.readline().rstrip().split()]
b_list = [int(x) for x in stdin.readline().rstrip().split()]


pricedown_list = []
for i in range(m):
    pricedown_list.append([int(x) for x in stdin.readline().rstrip().split()])


min_price = calc_min_price(a_list, b_list,  pricedown_list)


print(min_price)

Solution (Python):



from sys import stdin

def calc_ab_price_without_pricedown(a_list, b_list):
    ab_price = [[a_list[j]+b_list[i] for i in range(len(b_list))] for j in range(len(a_list))]

    return ab_price


def calc_pricedown(ab_price, pricedown_list):
    """値段表から値引きする"""
    for i, j, price in pricedown_list:
        for k, l, price2 in pricedown_list:
            if (i, j) == (k, l) and price >= price2:
                continue
            elif (i, j) == (k, l) and price < price2:
                price = 0

        ab_price[i-1][j-1] -= price

    return ab_price

def generate_table(a_list, b_list,  pricedown_list):
    min_a = min(a_list)
    min_b = min(b_list)
    min_price = min_a + min_b

    for i, j, price in pricedown_list:
        min_price = min(min_price, a_list[i-1]+b_list[j-1]-price)

    return min_price


def calc_min_price(a_list, b_list, ab_price):
    min_price = float('inf')
    for i in range(len(a_list)):
        for j in range(len(b_list)):
            min_price = min(ab_price[i][j], min_price)
    return min_price

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

a_list = [int(x) for x in stdin.readline().rstrip().split()]
b_list = [int(x) for x in stdin.readline().rstrip().split()]

pricedown_list = []
for i in range(m):
    pricedown_list.append([int(x) for x in stdin.readline().rstrip().split()])
    











min_price = generate_table(a_list, b_list,  pricedown_list)




print(min_price)

Solution (Python):
_, _, 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())
    kaikei = a[x-1] + b[y-1] - c
    if kaikei < ans:
        ans = kaikei

print(ans)

Solution (Python):
def main():
    A,B,M = map(int,input().split())
    val_a = [int(i) for i in input().split()]
    val_b = [int(j) for j in input().split()]
    lucky = [map(int,input().split()) for _ in range(M)]
    min_a = min(val_a)
    min_b = min(val_b)
    ans = min_a + min_b
    for i in range(M):
        a,b,c = lucky[i]
        p = val_a[a-1] + val_b[b-1] - c
        if p < ans:
            ans = p
    
    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()))
C = [list(map(int,input().split())) for _ in range(M)]
ans = min(A) + min(B)
for cp in C:
    temp = A[cp[0]-1] + B[cp[1]-1] - cp[2]
    ans = min(ans,temp)

print(ans)

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

ma=int(1000000)
mb=int(1000000)
for i in range(a):
    if A[i]<ma:
        ma=A[i]
for i in range(b):
    if B[i]<mb:
        mb=B[i]

ans=ma+mb

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

reizouko = list(map(int,input().split()))
renji = list(map(int,input().split()))

kupon_min = 10**11

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

normal_min = min(reizouko) + min(renji)

print(min(normal_min,kupon_min))

Solution (Python):
import sys
import numpy as np

read = sys.stdin.read
readline = sys.stdin.readline

A, B, M = map(int, readline().split())
a = np.array(readline().split(), np.int64)
b = np.array(readline().split(), np.int64)
xyc = np.array(read().split(), np.int64)
x = xyc[::3]
y = xyc[1::3]
c = xyc[2::3]
answer = np.min(a) + np.min(b)
answer = min(answer, np.min(a[x - 1] + b[y - 1] - c))
print(answer)

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

a_A = list(map(int, input().split()))
b_B = list(map(int, input().split()))

summ = min(a_A) + min(b_B)

x = []
y = []
c = []

for i in range(m):
    x, y, c = map(int, input().split())
    
    
    
    discount = a_A[x - 1] + b_B[y - 1] - int(c)

    if discount < summ:
        summ = discount

print(summ)

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

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

print(ans)

Solution (Python):
from sys import stdin

A, B, M = (int(x) for x in stdin.readline().rstrip().split())
ai = [int(x) for x in stdin.readline().rstrip().split()]
bj = [int(x) for x in stdin.readline().rstrip().split()]

minimum = min(ai) + min(bj)
for i in range(M):
    x, y, c = (int(x) for x in stdin.readline().rstrip().split())
    price = ai[x-1] + bj[y-1] - c
    if price < minimum:
        minimum = price

print(minimum)

Solution (Python):


a,b,m = [int(x) for x in input().split()]
an = [int(x) for x in input().split()]
bn = [int(x) for x in input().split()]

ans = min(an)+min(bn)
for i in range(m):
    p, q, discount = [int(x) for x in input().split()]
    a_cost = an[p-1]
    b_cost = bn[q-1]
    total = a_cost + b_cost - discount
    ans = min(total, ans)

print(ans)

Solution (Python):
a,b,m = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
mina = min(a)
minb = min(b)
ans = mina + minb
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())
al=list(map(int,input().split()))
bl=list(map(int,input().split()))
ans=min(al)+min(bl)
for i in range(m):
    c,d,x=map(int,input().split())
    ans=min(ans,al[c-1]+bl[d-1]-x)
print(ans)

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

if M == 0:
  exit()

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

Solution (Python):
A, B, M = list(map(int,input().split()))
list_a = list(map(int,input().split()))
list_b = list(map(int,input().split()))
buy = []
buy.append(min(list_a) + min(list_b))
for i in range(M):
    x, y, c = list(map(int,input().split()))
    buy.append(list_a[x-1] + list_b[y-1] - c)
answer = min(buy)
print(answer)

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

print(min)

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

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

sum_origin=min(a)+min(b)

sum_=[]

for x_,y_,c_ in x:
  
  sum_disc=a[x_-1]+b[y_-1]-c_
  sum_.append(sum_disc)

if min(sum_)>sum_origin:
  print(sum_origin)

elif min(sum_)<sum_origin: 
  print(min(sum_))

elif min(sum_) == sum_origin:
  print(min(sum_))

Solution (Python):
A,B,M = map(int,input().split())
a = [i for i in map(int,input().split())]
b = [i for i in map(int,input().split())]
xyc = [[i for i in map(int,input().split())] for j 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):
from collections import *
from itertools import *
from bisect import *
from heapq import *
import copy
import math
from fractions import gcd

_,__,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)]

value=min(A)+min(B)


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

Solution (Python):
x,y,m = map(int,input().split());an=10**9
p=list(map(int,input().split()));q=list(map(int,input().split()))
for i in range(m):
  a,b,c = map(int,input().split())
  an=min(an,p[a-1]+q[b-1]-c)
an=min(an,min(p)+min(q))
print(an)

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

x = [0] * M
y = [0] * M
c = [0] * M

ans = []
ans.append(min(a) + min(b))
for i in range(M):
    x[i], y[i], c[i] = [int(k) for k in input().split()]

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

print(min(ans))

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

Solution (Python):
def main():
    A,B,M = [int(n) for n in input().split()]
    arrA = [int(n) for n in input().split()]
    arrB = [int(n) for n in input().split()]
    arrC = []
    for i in range(M): 
        x,y,c = [int(n) for n in input().split()]
        x-=1
        y-=1
        arrC.append((x,y,c))
    res = min(arrA) + min(arrB)
    for i in range(M):
        wari = arrC[i]
        price = arrA[wari[0]] + arrB[wari[1]] - wari[2]
        res = min(res, price)
    print(res)
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 k in range(M):
    x, y, c = map(int, input().split())
    ans = min(ans, ((a[x - 1] + b[y - 1]) - c))
print(ans)

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

Solution (Python):
A,B,M=map(int, input().split())
a=list(map(int, input().split()))
b=list(map(int, input().split()))
c=[]
wari=[]
warik=0
ans=0
for i in range(M):
    c+=list(map(int, input().split()))
for i in range(M):
    wari.append(a[c[i*3]-1]+b[c[2*i+(i+1)]-1]-c[2+3*i])    
warik=min(wari)
ans=min(a)+min(b)
if ans<warik:
    print(ans)
else:
    print(warik)

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

Solution (Python):
def mi():return map(int,input().split())
A,B,M=mi()
a=list(mi())
b=list(mi())
ans=min(a)+min(b)
for _ in range(M):
    x,y,c=mi()
    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())

min_cost = min(a) + min(b)

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

print(min_cost)

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

print(ans)

Solution (Python):
import sys
def ipt():
    return map(int, sys.stdin.readline().strip().split())

_A, _B, m = ipt()
a = list(ipt())
b = list(ipt())
data = [list(ipt()) for _ in range(m)]
 
ans = min(a) + min(b)
for x, y, c in data:
  case = a[x-1] + b[y-1] - c
  ans = min(ans, case)
print(ans)

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

Solution (Python):
import sys

def resolve():
    input = sys.stdin.readline
    A, B, M = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    grid=[list(map(int,input().split())) for i in range(M)]

    res = min(a) + min(b)

    for x, y, c in grid:
        res = min(res, a[x-1]+b[y-1]-c)

    print(res)
    
resolve()

Solution (Python):


import sys
from collections import Counter

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N, M, L = MAP()
A = LIST()
B = LIST()

mn = min(A) + min(B)
for _ in range(L):
    x, y, c = MAP()
    x -= 1; y -= 1
    mn = min(mn, A[x] + B[y] - c)
print(mn)

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

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

an = list(map(int, input().split(' ')))
bn = list(map(int, input().split(' ')))

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







total = min(an) + min(bn)

for a,b,c in mn:
    total = min(total, an[a-1]+bn[b-1]-c)
print(total)

Solution (Python):
import sys
input=sys.stdin.readline
from itertools import accumulate
sys.setrecursionlimit(100000000)

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
        tmp=a[x]+b[y]-c
        ans=min(tmp,ans)
    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()))
min_a = min(a)
min_b = min(b)
ans = min_a + min_b
for _ in range(M):
    i, j, c = map(int, input().split())
    ans = min(ans, a[i - 1] + b[j - 1] - c)
print(ans)

Solution (Python):

A, B, M = map(int, input().split())
Ma = [int(_) for _ in input().split()]
Mb = [int(_) for _ in input().split()]
Mm = [[int(_) for _ in input().split()] for __ in range(M)]

r0 = min(Ma) + min(Mb)

r1 = min([Ma[x-1]+Mb[y-1]-c for x,y,c in Mm])
print(min(r0,r1))

Solution (Python):
import sys
 
A, B, M = map(int, sys.stdin.readline().split())
*a, = map(int, sys.stdin.readline().split())
*b, = map(int, sys.stdin.readline().split())
xyc = zip(*[map(int, sys.stdin.read().split())] * 3)
 
def main():
    res = min(a) + min(b)
 
    for x, y, c in xyc:
        res = min(res, a[x-1] + b[y-1] - c)
    return res
    
if __name__ == '__main__':
    ans = main()
    print(ans)

Solution (Python):
A, B, M = [int(n) for n in input().split()]
a  = [int(n) for n in input().split()]
b = [int(n) for n in input().split()]
ma = sorted(a)[0]
mb = sorted(b)[0]
ans = ma + mb
for m in range(M):
    x, y, c = [int(n) for n in input().split()]
    dv = a[x-1] + b[y-1] - c
    ans = min(ans , dv)
print(ans)

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

    res = min(a) + min(b)

    for x, y, c in grid:
        res = min(res, a[x-1]+b[y-1]-c)

    print(res)
    
resolve()

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

mn = [min(a) + min(b)]

for value in xyc:
    mn.append(a[value[0] - 1] + b[value[1] - 1] - value[2])

print(min(mn))