Problem:
 Score : 200 points    Problem Statement  You are visiting a large electronics store to buy a refrigerator and a microwave.  The store sells A kinds of refrigerators and B kinds of microwaves. The i -th refrigerator ( 1 \le i \le A ) is sold at a_i yen (the currency of Japan), and the j -th microwave ( 1 \le j \le B ) is sold at b_j yen.  You have M discount tickets. With the i -th ticket ( 1 \le i \le M ), you can get a discount of c_i yen from the total price when buying the x_i -th refrigerator and the y_i -th microwave together. Only one ticket can be used at a time.  You are planning to buy one refrigerator and one microwave. Find the minimum amount of money required.      Constraints   All values in input are integers.  1 \le A \le 10^5  1 \le B \le 10^5  1 \le M \le 10^5  1 \le a_i , b_i , c_i \le 10^5  1 \le x_i \le A  1 \le y_i \le B  c_i \le a_{x_i} + b_{y_i}         Input  Input is given from Standard Input in the following format:  A  B  M  a_1  a_2  ...  a_A  b_1  b_2  ...  b_B  x_1  y_1  c_1  \vdots  x_M  y_M  c_M       Output  Print the answer.        Sample Input 1 2 3 1
3 3
3 3 3
1 2 1      Sample Output 1 5  With the ticket, you can get the 1 -st refrigerator and the 2 -nd microwave for 3+3-1=5 yen.       Sample Input 2 1 1 2
10
10
1 1 5
1 1 10      Sample Output 2 10  Note that you cannot use more than one ticket at a time.       Sample Input 3 2 2 1
3 5
3 5
2 2 2      Sample Output 3 6  You can get the 1 -st refrigerator and the 1 -st microwave for 6 yen, which is the minimum amount to pay in this case.
Note that using a ticket is optional.

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

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

As = list(map(int,input().split()))
Bs = list(map(int,input().split()))
XYC = []
min_cost = 10**10
for i in range(M):
    x,y,c = map(int,input().split())
    cost = As[x-1] + Bs[y-1]-c
    min_cost = min(min_cost,cost)
min_cost = min(min_cost,min(As)+min(Bs))
print(min_cost)

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

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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    A,B,M=MI()
    a=LI()
    b=LI()
    ans=min(a)+min(b)
    for i in range(M):
        x,y,c=MI()
        x-=1
        y-=1
        temp=a[x]+b[y]-c
        if ans>temp:
            ans=temp
    print(ans)

main()

Solution (Python):
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): 
    return list(map(int,input().split()))
def m(): 
    return map(int,input().split())
def onem(): 
    return int(input())
def s(x): 
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): 
    return " ".join(map(str,x))
def max2(x): 
    return max(map(max,x))
def In(x,a): 
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False
"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""
A,B,M = m()
a = l()
b = l()

po = min(a) + min(b)

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

print(po)

Solution (Python):

import sys
input = sys.stdin.buffer.readline


from collections import defaultdict

con = 10 ** 9 + 7

def getlist():
	return list(map(int, input().split()))


def main():
	A, B, M = getlist()
	a = getlist()
	b = getlist()
	am = min(a)
	bm = min(b)
	ans = am + bm
	for i in range(M):
		x, y, c = getlist()
		ans = min(ans, a[x - 1] + b[y - 1] - c)

	print(ans)
	


if __name__ == '__main__':
	main()

Solution (Python):
import sys

def solve():
    input = sys.stdin.readline
    A, B, M = map(int, input().split())
    A = [int(a) for a in input().split()]
    B = [int(b) for b in input().split()]
    minP = min(A) + min(B)
    for _ in range(M):
        x, y, c = map(int, input().split())
        minP = min(A[x-1] + B[y-1] - c, minP)
    print(minP)

    return 0

if __name__ == "__main__":
    solve()

Solution (Python):
import sys
input = sys.stdin.readline
def main():
    A, B, M = map( int, input().split())
    a = list( map( int, input().split()))
    b = list( map( int, input().split()))
    X = [ tuple( map( int, input().split())) for _ in range(M)]
    ans = min(a) + min(b)
    for x, y, c in X:
        if a[x-1] + b[y-1] - c < ans:
            ans = a[x-1] + b[y-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()))
ans = 10**9
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)

Solution (Python):
def main():

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

if __name__ == '__main__':
    print(main())

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

Solution (Python):
A,B,M = list(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)]

min_val = min(a) + min(b)


for x,y,c in XYC:
    min_val = min(min_val,
                  a[x-1]+b[y-1]-c)
print(min_val)

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

ans = min(a) + min(b)

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

mmA = min(A)
mmB = min(B)

ans = mmA+mmB

for i in range(M):
    x,y,c = map(int,input().split())
    x-=1
    y-=1

    mm = A[x]+B[y]-c
    ans = min(ans,mm)

print(ans)

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

Solution (Python):
a,b,m=map(int,input().split())
s=list(map(int,input().split()))
t=list(map(int,input().split()))
d=min(s)+min(t)
for i in range(m):
    p,q,r=map(int,input().split())
    d=min(d,s[p-1]+t[q-1]-r)
print(d)

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):
aa, bb, m = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))

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

ans = 10 ** 19
for i in range(m):
    x, y, c = info[i]
    x -= 1
    y -= 1
    ans = min(ans, a[x] + b[y] - c)
a_min = min(a)
b_min = min(b)
ans = min(ans, a_min + b_min)
print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(700000)

def s_in():
    return input()

def n_in():
    return int(input())

def l_in():
    return list(map(int, input().split()))

def print_l(l):
    print(' '.join(map(str, l)))

class Interval():
    def __init__(self, li):
        self.li = li
        self.n = len(li)
        self.sum_li = [li[0]]
        for i in range(1, self.n):
            self.sum_li.append(self.sum_li[i-1] + li[i])

    def sum(self, a, b=None):
        if b is None:
            return self.sum(0, a)

        res = self.sum_li[min(self.n-1, b-1)]
        if a > 0:
            res -= self.sum_li[a-1]
        return res

a,b,m = l_in()
A = l_in()
B = l_in()

res = min(A)+min(B)

for _ in range(m):
    x,y,c = l_in()
    res = min(res, A[x-1]+B[y-1]-c)
print(res)

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

As = list(map(int, input().split()))
Bs = list(map(int, input().split()))
Ms = [list(map(int, input().split())) for _ in range(M)]

ans = min(As) + min(Bs)
for a, b, c in Ms:
    p = As[a-1] + Bs[b-1] - c
    ans = ans if ans < p else p
print(ans)

Solution (Python):
import sys
a, b, m = [int(i) for i in sys.stdin.readline().split()]
a_ls = [int(i) for i in sys.stdin.readline().split()]
b_ls = [int(i) for i in sys.stdin.readline().split()]
best = min(a_ls) + min(b_ls)
for i in range(m):
    x, y, c = [int(i) for i in sys.stdin.readline().split()]
    x -= 1
    y -= 1
    best = min(best, a_ls[x] + b_ls[y] - c)
print(best)

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

ans = min(a)+min(b)

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



import array
from bisect import *
from collections import *
import fractions
import heapq
from itertools import *
import math
import random
import re
import string
import sys

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 m in range(M):
    x, y, c = map(int, input().split())
    tmp = As[x - 1] + Bs[y - 1] - c
    ans = min(ans, tmp)
print(ans)

Solution (Python):
A, B, M = map(int, raw_input().split())
a = map(int, raw_input().split())
b = map(int, raw_input().split())
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

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

Solution (Python):

import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1

def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(A, B, XYC):
    ans = min(A) + min(B)
    for x, y, c in XYC:
        t = A[x-1] + B[y-1] - c
        ans = min(t, ans)
    return ans


def main():
    A, B, M = read_int_n()
    A = read_int_n()
    B = read_int_n()
    XYC = [read_int_n() for _ in range(M)]
    print(slv(A, B,XYC))


if __name__ == '__main__':
    main()

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

ans = min(a) + min(b)

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

Solution (Python):

import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

a,b,m = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
a = min(A); b=min(B)
mans = a+b
for _ in range(m):
  x,y,c = map(int,input().split())
  x-=1;y-=1
  tmp = A[x] + B[y] - c
  mans = min(mans,tmp)
print(mans)

Solution (Python):

import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
def input(): return sys.stdin.readline().rstrip()

def main():
    A,B,M=map(int,input().split())
    a=list(map(int,input().split()))
    b=list(map(int,input().split()))
    ans=INF
    for i in range(M):
        x,y,c=map(int,input().split())
        x-=1; y-=1
        ans=min(ans,a[x]+b[y]-c)
    a.sort()
    b.sort()
    ans=min(ans,a[0]+b[0])
    print(ans)

if __name__ == '__main__':
    main()

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

Solution (Python):
def main():
    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()))
    ans = min(A) + min(B)
    for _ in range(M):
        x, y, c = map(int, input().split())
        ans = min(ans, A[x-1] + B[y-1] - c)
    print(ans)



if __name__ == '__main__':
    main()

Solution (Python):
import sys
def input():
	return sys.stdin.readline()[:-1]

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

Solution (Python):
def main():
    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 [0]*m]
    ans = min(a)+min(b)
    for x, y, c in xyc:
        ans = min(ans, a[x-1]+b[y-1]-c)
    print(ans)


main()

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

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

Solution (Python):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**5)

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

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

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

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

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


if __name__ == '__main__':
    main()

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

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

ans = min(a) + min(b)

for i in range(M):

    x,y,c = map(int,input().split())

    x -= 1
    y -= 1

    ans = min(ans , a[x]+b[y]-c)

print (ans)

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

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

print(ans)

Solution (Python):
import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__


a,b,m = map(int, input().split())
aa = list(map(int, input().split()))
bb = list(map(int, input().split()))
ans = min(aa) + min(bb)

for i in range(m):
    x,y,c = map(int, input().split())
    x,y = x-1, y-1
    tmp = aa[x] + bb[y] - 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()))
mina = min(a)
minb = min(b)
cand = [mina + minb]
for i in range(M):
    x,y,c= map(int,input().split())
    cand.append(a[x-1] + b[y-1] -c)

print(min(cand))

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

Solution (Python):
a,b,m = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
ans = 10**10
for i in range(m):
    x,y,c = map(int,input().split())
    x -= 1
    y -= 1
    ans = min(ans,a[x]+b[y]-c)
ans = min(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()))
ans=min(aa)+min(bb)
for i in range(m):
    x,y,z=map(int,input().split())
    ans=min(ans,max(0,aa[x-1]+bb[y-1]-z))
print(ans)

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

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

ANS=min(A)+min(B)
for x,y,c in W:
    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())
    pay = a[x - 1] + b[y - 1] - c
    ans = min(ans, pay)

print(ans)

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

ans = 10**15
for l in L:
    ans = min(ans, A[l[0]-1]+B[l[1]-1]-l[2])
ans = min(ans, min(A)+min(B))
print(ans)

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

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

ans = min(A) + min(B)
for x,y,c in XYC:
    x,y = x-1,y-1
    p = A[x] + B[y] - c
    ans = min(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()))

mi = min(a) + min(b)

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

print(mi)

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

a,b,m = map(int,readline().split())
lst1 = list(map(int,readline().split()))
lst2 = list(map(int,readline().split()))
lst3 = []
for i in range(m):
    x,y,c = map(int,readline().split())
    lst3.append(lst1[x-1]+lst2[y-1]-c)

amin = min(lst1)
bmin = min(lst2)

abmin = min(lst3)

print(min(amin+bmin,abmin))

Solution (Python):
def main():
    _, _, M = list(map(int, input().split()))
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    m = 10**9
    for _ in range(M):
        x, y, c = list(map(int, input().split()))
        m = min(A[x - 1] + B[y - 1] - c, m)
    m = min(m, min(A) + min(B))
    return m

print(main())

Solution (Python):
def main():
    A,B,M=map(int, input().split())
    AS=list(map(int, input().split()))
    BS=list(map(int, input().split()))
    XYC=[tuple(map(int, input().split()))for _ in range(M)]
    ans=min(AS)+min(BS)
    for x,y,c in XYC:
        ans=min(ans, AS[x-1]+BS[y-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()))

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

print(ans)

Solution (Python):
import sys

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7


A, B, M = MI()
A = LMI()
B = LMI()

minA = min(A)
minB = min(B)
ans = minA + minB
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, b = [list(map(int, input().split()))for i in range(2)]

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

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

Solution (Python):
import bisect
import cmath
import heapq
import itertools
import math
import operator
import os
import random
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7



NA, NB, M = list(map(int, sys.stdin.buffer.readline().split()))
A = list(map(int, sys.stdin.buffer.readline().split()))
B = list(map(int, sys.stdin.buffer.readline().split()))
XYC = [list(map(int, sys.stdin.buffer.readline().split())) for _ in range(M)]

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

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

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

A, B, M = map(int, readline().split()) 
aa = list(map(int, readline().split()))
bb = list(map(int, readline().split()))

res = min(aa) + min(bb)

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

print(res)

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

Solution (Python):

from collections import defaultdict,deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    A,B,m = LI()
    a = LI()
    b = LI()
    ans = min(a)+min(b)
    g = LIR(m)
    for i,j,c in g:
        i -= 1
        j -= 1
        k = a[i]+b[j]-c
        if k < ans:
            ans = k
    print(ans)
    return


if __name__ == "__main__":
    solve()

Solution (Python):











import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log 
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    A,B,M=MI()
    A=LI()
    B=LI()
    ans = min(A)+min(B)
    for i in range(M):
        a,b,c=MI()
        ans = min(ans, A[a-1]+B[b-1]-c)
    print(ans)
if __name__ == '__main__':
    main()

Solution (Python):
def inpl():
    return list(map(int, input().split()))


A, B, M = inpl()
A = inpl()
B = inpl()
xyc = [inpl() for _ in range(M)]

tmp = min(A) + min(B)

for x, y, c in xyc:
    tmp = min(tmp, A[x - 1] + B[y - 1] - c)

print(tmp)

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

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

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

print(ans)

Solution (Python):
A,B,m=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
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)