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

Solution (Python):
a,b,m = map(int, input().split())
a_lis = list(map(int, input().split()))
b_lis = list(map(int, input().split()))
ans_lis = [min(a_lis)+min(b_lis)]
for _ in range(m):
    x,y,z = map(int, input().split())
    tmp = a_lis[x-1]+b_lis[y-1]-z
    ans_lis.append(tmp)
print(min(ans_lis))

Solution (Python):
from collections import defaultdict
from collections import deque
from string import ascii_uppercase
import sys, bisect, math, heapq

stdin = sys.stdin
read_int = lambda : list(map(int,stdin.readline().split()))
read_str = lambda : stdin.readline().rstrip()

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

def solve():
    ans = min(a) + min(b)
    for x, y, c in xyc:
        ans = min(a[x - 1] + b[y - 1] - c, ans)
    return ans

if __name__ == "__main__":
    print(solve())

Solution (Python):
n,m,c=map(int,input().split())

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

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

tmp=a_min+b_min

for i in range(c):
  i,j,k=map(int,input().split())
  i-=1
  j-=1
  tmp=min(tmp,a[i]+b[j]-k)
print(tmp)

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

Solution (Python):

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

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

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

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

z=[0]*M

p=min(a)+min(b)

for i in range(M):
    z[i]=a[d[i][0]-1]+b[d[i][1]-1]-d[i][2]

q=min(z)


print(min(p,q))

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

ans = 3*(10**5)

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

aaa = sorted(aaa)
bbb = sorted(bbb)

ans = min(ans,aaa[0]+bbb[0])
print(ans)

Solution (Python):
from collections import defaultdict, Counter, deque

NA, NB, NM = list(map(int, input().split()))

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


best = min(A) + min(B)

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


print(best)

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

o = min(a_list) + min(b_list)
for _ in range(M):
    x, y, c = map(int, input().split())
    t_a = a_list[x-1]
    t_b = b_list[y-1]
    r = t_a + t_b - c
    if o is None or o > r:
        o = r


print(o)

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

a_list = [int(e) for e in input().split()]
b_list = [int(e) for e in input().split()]

min_price = min(a_list)+min(b_list)

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

Solution (Python):
import numpy as np
import collections

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


answer=0
x=[]
y=[]
c=[]

answer = min(a)+min(b)

for i in range(M):
    x1,y1,c1 = map(int,input().split())
    if a[x1-1]+b[y1-1]-c1 < answer:
        answer = a[x1-1]+b[y1-1]-c1




print(answer)

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 = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
discount = 10000000000
for i in range(M):
    C = [int(i) for i in input().split()]
    num = a[C[0]-1] + b[C[1]-1] -C[2]
    if discount > num:
        discount = num
a.sort()
b.sort()
if discount > a[0]+b[0]:
    discount = a[0]+b[0]
print(discount)

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

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

    ans = min(A) + min(B)

    for i in range(m):
        ticket = discount[i]
        tmp = A[ticket[0] - 1] + B[ticket[1] - 1] - ticket[2]
        if ans > tmp:
            ans = tmp

    print(ans)


if __name__ == '__main__':
    main()

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

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

Solution (Python):
def f():
    def getMin(A):
        minA = A[0]
        for a in A:
            minA = min(minA,a)
        return minA
    la, lb, lc = [int(s) for s in input().split()]
    A = [int(s) for s in input().split()]
    B = [int(s) for s in input().split()]
    mina = getMin(A)
    minb = getMin(B)
    ans = mina+minb
    for i in range(lc):
        x, y, c = [int(s) for s in input().split()]
        p = A[x-1]+B[y-1]-c
        ans = min(ans,p)
    print(ans)


f()

Solution (Python):
A, B, M = [int(i) for i in input().split()]
Aa = [int(i) for i in input().split()]
Bb = [int(i) for i in input().split()]
XYCm = [[int(i) for i in input().split()] for _ in range(M)]

minA = min(Aa)
minB = min(Bb)

min_value = minA + minB
for x, y, c in XYCm:
  tot = Aa[x-1] + Bb[y-1] - c
  min_value = min(min_value, tot)
print(min_value)

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

answer=min(a)+min(b)

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

print(answer)

Solution (Python):
def resolve():
    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(max(ans, 0))


if __name__ == '__main__':
    resolve()

Solution (Python):
a, b, m = map(int, input().split())
rei = list(map(int, input().split()))
den = list(map(int, input().split()))
cup = [tuple(map(int, input().split())) for _ in range(m)]

ans = 10 ** 9
for x, y, c in cup:
    ans = min(ans, rei[x-1] + den[y-1] - c)
ans = min(ans, min(rei) + min(den))
print(ans)

Solution (Python):


reizouNum, rangeNum, waribikiNum = map(int, input().split())

reizous = list(map(int, input().split()))
ranges = list(map(int, input().split()))

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



ans = 0
minreizou = min(reizous)
minrange = min(ranges)

ans = minreizou + minrange

for rei, rai, discount in waribikis:
    cost = reizous[rei-1] + ranges[rai-1] - discount
    ans = min(ans, cost)

print(ans)

Solution (Python):
import math
from collections import deque
def main():
    a,b,m = tuple([int(t)for t in input().split()])

    a_i = [int(t)for t in input().split()]
    b_i = [int(t)for t in input().split()]

    pairs = []
    for _ in range(m):
        pairs.append(tuple([int(t)for t in input().split()]))

    candidates = [min(a_i)+min(b_i)]

    for x,y,c in pairs:
        candidates.append(a_i[x-1]+b_i[y-1]-c)

    print(min(candidates))

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

res = 10**9
for i in range(M):
    x, y, c = map(int, input().split())
    x, y = x - 1, y - 1
    res = min(res, An[x] + Bn[y] - c)

a_m, b_m = min(An), min(Bn)

res = min(res, a_m + b_m)
print(res)

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

min_r = min(reizo)
min_d = min(densi)
max_all = min_r + min_d

for i in range(M):
  x, y, c = map(int,input().split())
  discount = reizo[x - 1] + densi[y -1] - c
  if max_all > discount:
    max_all = discount

print(max_all)

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

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

Solution (Python):

import sys


def solve(A: int, B: int, M: int, a: "List[int]", b: "List[int]", x: "List[int]", y: "List[int]", c: "List[int]"):
    m = min(a) + min(b)
    for i in range(M):
        m = min(a[x[i]-1] + b[y[i]-1] - c[i], m)
    print(m)
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  
    B = int(next(tokens))  
    M = int(next(tokens))  
    a = [int(next(tokens)) for _ in range(A)]  
    b = [int(next(tokens)) for _ in range(B)]  
    x = [int()] * (M)  
    y = [int()] * (M)  
    c = [int()] * (M)  
    for i in range(M):
        x[i] = int(next(tokens))
        y[i] = int(next(tokens))
        c[i] = int(next(tokens))
    solve(A, B, M, a, b, x, y, c)

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

amin = min(a)
bmin = min(b)

ans = amin + bmin

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

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

ans = a_min + b_min

x = 0
y = 1
c = 2
for t in ticket:
    set_price = a[t[x] - 1] + b[t[y] - 1] - t[c]
    ans = min(ans, set_price)

print(ans)

Solution (Python):
a, b, m = map(int, input().split())
ali = list(map(int, input().split()))
bli = list(map(int, input().split()))
xyc = [[int(i) for i in input().split()] for i in range(m)]
li = [0] * (m + 1)
for i in range(m):
    li[i] = ali[xyc[i][0] - 1] + bli[xyc[i][1] - 1] - xyc[i][2]
li[m] = min(ali) + min(bli)
print(min(li))

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


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

Solution (Python):
a, b, m = map(int, input().split())
aa = list(map(int, input().split()))
bb = list(map(int, input().split()))
xx = [0] * m
yy = [0] * m
cc = [0] * m
for i in range(m):
    xx[i], yy[i], cc[i] = map(int, input().split())

ans = min(aa) + min(bb)
for i in range(m):
    ans = min(ans, aa[xx[i] - 1]+ bb[yy[i] - 1] - cc[i])
print(ans)

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

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


mini=min(aa)+min(bb)

for _ in range(m):
  x,y,c=map(int,input().split())
  mini=min(mini,aa[x-1]+bb[y-1]-c)
print(mini)

Solution (Python):
A,B,M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
cheapest = min(a) + min(b)
for i in range(M):
    l,m,n = map(int, input().split())
    x = a[l-1] + b[m-1]- n
    if x < cheapest:
        cheapest = x
print(cheapest)

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

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

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

Solution (Python):
A, B, M = map(int, input().split())
As = list(map(int, input().split()))
Bs = list(map(int, input().split()))
min_p = min(As)+min(Bs)
for i in range(M):
  a, b, m = map(int, input().split())
  min_p = min(As[a-1]+Bs[b-1]-m,  min_p)
print(min_p)

Solution (Python):
import sys

A, B, m = map(int, input().split())
a = [int(i) for i in sys.stdin.readline().rstrip().split()]
b = [int(i) for i in sys.stdin.readline().rstrip().split()]
ans = min(a) + min(b)
for i in range(m):
    x, y, c = map(int, input().split())
    tmp = a[x-1] + b[y-1] - c
    if tmp < ans:
        ans = tmp

print(ans)

Solution (Python):
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    a,b,m = map(int, readline().split())
    A = [int(i) for i in readline().split()]
    B = [int(i) for i in readline().split()]

    t = min(A) + min(B)
    ans = 10**6
    for i in range(m):
        x,y,c = map(int, readline().split())
        tmp = A[x-1] + B[y-1] - c
        ans =min(ans, tmp)
    
    print(min(ans,t))

if __name__ == "__main__":
    main()

Solution (Python):
a, b, m = map(int, input().split())
a_lst = list(map(int, input().split()))
b_lst = list(map(int, input().split()))
waribiki = []
for i in range(m):
    waribiki.append(list(map(int, input().split())))

no_waribiki = min(a_lst) + min(b_lst)

yes_waribiki = 100000000
for i in range(m):
    yes_waribiki = min(yes_waribiki, a_lst[waribiki[i][0]-1] + b_lst[waribiki[i][1]-1] - waribiki[i][2])

print(min(no_waribiki, yes_waribiki))

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

a_l = list(map(int, input().split()))
b_l = list(map(int, input().split()))

minpay = min(a_l) + min(b_l)
for i in range(m):
    c_l = list(map(int, input().split()))
    if a_l[c_l[0] - 1] + b_l[c_l[1] - 1] - c_l[2] <= minpay:
        minpay = a_l[c_l[0] - 1] + b_l[c_l[1] - 1] - c_l[2]

print(minpay)

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

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

cost_a = list(map(int, input().split()))
cost_b = list(map(int, input().split()))

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

print(ans)

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

print(ans)

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

Solution (Python):
A,B,M = map(int,input().split())
AA = list(map(int,input().split()))
BB = list(map(int,input().split()))
C = [list(map(int,input().split())) for _ in range(M)]

ans = min(AA)+min(BB)
for x,y,c in C:
  x -= 1
  y -= 1
  ans = min(AA[x]+BB[y]-c,ans)
print(ans)

Solution (Python):
a, b, m = map(int, input().split())
a_l = list(map(int, input().split()))
b_l = list(map(int, input().split()))
coupons = [list(map(int, input().split())) for _ in range(m)]

ans = min(a_l) + min(b_l)
pairs = []
for a_i, b_i, c in coupons:
    pairs.append(a_l[a_i-1]+b_l[b_i-1]-c)

print(min(ans, min(pairs)))

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 = 10**19
for i in range(m):
  x, y, c = map(int,input().split())
  ans = min(A[x-1]+B[y-1]-c, ans)
print(min(ans,min(A)+min(B)))

Solution (Python):

A, B, M = map(int,(input().split()))
al = list(map(int,(input().split())))
bl = list(map(int,(input().split())))
xyms = []
for _ in range(M):
    xyms.append(list(map(int,(input().split()))))


ans = min(al) + min(bl)
for xym in xyms:
    x = xym[0]
    y = xym[1]
    m = xym[2]
    ans = min(al[x-1] + bl[y-1] - m, ans)


print(ans)

Solution (Python):

import sys



def solve(A: int, B: int, M: int, a: "List[int]", b: "List[int]", x: "List[int]", y: "List[int]", c: "List[int]"):
    m1=min(a)+min(b)
    for i in range(M):
        m1=min(m1,a[x[i]-1]+b[y[i]-1]-c[i])
        
    print(m1)

    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  
    B = int(next(tokens))  
    M = int(next(tokens))  
    a = [int(next(tokens)) for _ in range(A)]  
    b = [int(next(tokens)) for _ in range(B)]  
    x = [int()] * (M)  
    y = [int()] * (M)  
    c = [int()] * (M)  
    for i in range(M):
        x[i] = int(next(tokens))
        y[i] = int(next(tokens))
        c[i] = int(next(tokens))
    solve(A, B, M, a, b, x, y, c)

if __name__ == '__main__':
    main()

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

m1 = 10000000000
m2 = 10000000000
for i in al: m1 = min(m1, i)
for i in bl: m2 = min(m2, i)

ans = m1 + m2


for i in range(m):
    x, y, z = map(int, input().split())
    t = al[x-1]+bl[y-1]-z
    ans = min(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(' ')))

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

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

print(ans)

Solution (Python):
import numpy as np

A, B, M = map(int, input().split())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
minimum = np.min(a) + np.min(b)
for i in range(M):
    x,y,c = map(int, input().split())
    price = a[x-1] + b[y-1] - c
    if price < minimum:
        minimum = price

print(minimum)

Solution (Python):


import queue



def main():
    a, b, m = map(int, input().split())
    ref = list(map(int, input().split()))
    ren = list(map(int, input().split()))
    minv = min(ref) + min(ren)
    
    for _ in range(m):
        x, y, c = map(int, input().split())
        minv = min(ref[x - 1] + ren[y - 1] - c, minv)
        
    print(minv)
    
    
if __name__ == '__main__':
    main()

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

ans = min(price_A) + min(price_B)

for _ in range(M):
    x, y, c = map(int, input().split())
    tmp = price_A[x-1] + price_B[y-1] - c
    if ans > tmp:
        ans = tmp
        
print(ans)

Solution (Python):


import sys
iim = lambda: map(int, sys.stdin.readline().rstrip().split())

def resolve():
    AN, BN, M = iim()
    A = list(iim())
    B = list(iim())

    ans = min(A) + min(B)

    for i in range(M):
        ai, bi, ci = iim()

        xi = A[ai-1] + B[bi-1] -ci
        ans = min(ans, xi)
    print(ans)

if __name__ == "__main__":
    resolve()

Solution (Python):
A,B,m=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
ans=10**7
for i in range(m):
    x,y,c=map(int,input().split())
    price=a[x-1]+b[y-1]-c
    if price<ans:
        ans=price
a.sort()
b.sort()
p=a[0]+b[0]
if p<ans:
    ans=p
print(ans)

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

print(ans)

Solution (Python):
a,b,m = map(int, input().split())
A = [int(x) for x in input().split()]
B = [int(x) for x in 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 = 10**6
for i in range(m):
    p = x[i]-1
    q = y[i]-1
    ans = min(ans, A[p]+B[q]-c[i])

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

Solution (Python):
a,b,m=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
ans=min(a)+min(b)
for _ 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()))
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()))

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

print(mini)

Solution (Python):






import math
from functools import lru_cache





MOD = 10**9 +7
INF = float('inf')





kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr





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

  
mini = min(a) + min(b)

for q in m:
  if a[q[0]-1] + b[q[1]-1] - q[2] < mini:
    mini = a[q[0]-1] + b[q[1]-1] - q[2]
    
print(mini)

Solution (Python):
A, B, M = [int(_) for _ in input().split()]
aA = [int(_) for _ in input().split()]
aB = [int(_) for _ in input().split()]
XYC = [[int(_) for _ in input().split()] for _ in range(M)]
ans = min(aA) + min(aB)
for x, y, c in XYC:
    ans = min(ans, aA[x - 1] + aB[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()]
x = [0 for i in range(M)]
y = [0 for i in range(M)]
c = [0 for i in range(M)]

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

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

print(ans)

Solution (Python):
a,b,m=map(int,input().split())
la=list(map(int,input().split()))
lb=list(map(int,input().split()))
l=[list(map(int,input().split())) for i in range(m)]
ans=[]
f=0
ma=min(la)
mb=min(lb)
for i in range(m):
  ans.append(la[l[i][0]-1]+lb[l[i][1]-1]-l[i][2])
  if la[l[i][0]-1]==ma and lb[l[i][1]-1]==mb:
    f=1
if f==0:
  ans.append(ma+mb)
print(min(ans))

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

ans = min(A) + min(B)

for _ in range(m):
    x, y, c = map(int, input().split())
    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 = [tuple(map(int, input().split())) for _ in range(M)]

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

print(ans)

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

ans = 0
ans = min(a) + min(b)


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

print(ans)

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

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

base = min(a) + min(b)
answer = base

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

Solution (Python):

import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline

























def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))

inf = float('inf')
mod = 1000000007




def main():
	A,B,M = inputMap()
	a = inputList()
	b = inputList()

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

	print(ans)









def combination(n, r, mod=10**9+7):
    r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i+1, mod) % mod
    return res


def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)

def egcd(a, b):
    if a == 0:
        return b, 0, 1
    else:
        g, y, x = egcd(b % a, a)
        return g, x - (b // a) * y, y



def H(n, r, mod=10**9+7):
	
	
    return combination(n+r-1, r, mod)

class Combination:
    """
    O(n)の前計算を1回行うことで，O(1)でnCr mod mを求められる
    n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
    使用例：
    comb = Combination(1000000)
    print(comb(5, 3))  
    """
    def __init__(self, n_max, mod=10**9+7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

    def make_factorial_list(self, n):
        
        
        fac = [1]
        facinv = [1]
        for i in range(1, n+1):
            fac.append(fac[i-1] * i % self.mod)
            facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        
        modinv = [0] * (n+1)
        modinv[1] = 1
        for i in range(2, n+1):
            modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
        return modinv

if __name__ == "__main__":
	main()