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 = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
x = []
y = []
c = []
for i in range(m):
	xs,ys,cs = map(int,input().split())
	x.append(xs)
	y.append(ys)
	c.append(cs)

ans1 = 10**10
for j in range(m):
	if ans1 >= a[x[j]-1] + b[y[j]-1] - c[j]:
		ans1 = a[x[j]-1] + b[y[j]-1] - c[j]
ans2 = min(a)+min(b)
print(min(ans1,ans2))

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

price_A = list(map(int, input().split()))
price_B = list(map(int, input().split()))
min_A = min(price_A)
min_B = min(price_B)

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

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)
temp=0

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

print(ans)

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

Solution (Python):
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()

from collections import defaultdict, deque, Counter
from sys import exit
import heapq
import math
import fractions
import copy
from itertools import permutations
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

A, B, M = getNM()

ref_a = getList()
ref_b = getList()

ticket = [getList() for i in range(M)]

ans = min(ref_a) + min(ref_b)
for i in ticket:
    opt = ref_a[i[0] - 1] + ref_b[i[1] - 1] - i[2]
    ans = min(ans, opt)
print(ans)

Solution (Python):
A,B,M = map(int,input().split())
Ai = list(map(int,input().split()))
Bi = list(map(int,input().split()))
amin = min(Ai)
bmin= min(Bi)
min = amin+bmin
for i in range(M):
	xi,yi,ci = map(int,input().split())
	if Ai[xi-1] + Bi[yi-1] - ci < min:
		min = Ai[xi-1] + Bi[yi-1] - ci
print(min)

Solution (Python):

_, _, M = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
X = []
Y = []
C = []
amin = min(A)
bmin = min(B)
for i in range(M):
    x, y, c = map(int, input().split())
    X.append(x)
    Y.append(y)
    C.append(c)

ans = amin+bmin
for i in range(M):
    if ans >= A[X[i]-1]+B[Y[i]-1]-C[i]:
        ans = A[X[i]-1]+B[Y[i]-1]-C[i]
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):
    x,y,c = map(int, input().split())
    ans = min(ans, al[x-1]+bl[y-1]-c)
print(ans)

Solution (Python):
A, B, m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = min(a) + min(b)
for _ in range(m):
    x, y, c= map(int, input().split())
    ans = min(a[x - 1] + b[y - 1] - c, ans)
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 nesya in range(m)]
cheap = min(a)+min(b)
for hoge in xyc:
  ch = a[hoge[0]-1]+b[hoge[1]-1]-hoge[2]
  cheap = min(ch,cheap)
print(cheap)

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

inf = float("inf")
posibility = inf

for m in range(M):
    x,y,c=map(int,input().split())
    tmp_posibility=A_li[x-1]+B_li[y-1]-c
    posibility=min(posibility,tmp_posibility)
 

no_c = min(A_li)+min(B_li)
decition = min(posibility,no_c)

print(decition)

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

inf = float("inf")
posibility = inf

for m in range(M):
    x,y,c=map(int,input().split())
    tmp_posibility=A_li[x-1]+B_li[y-1]-c
    posibility=min(posibility,tmp_posibility)
 

no_c = min(A_li)+min(B_li)
decition = min(posibility,no_c)

print(decition)

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


minc=min(a)+min(b)

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

print(minc)

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



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

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

    print(min_cost)


if __name__ == "__main__":
    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()]
min = min(A)+min(B)
for i in range(M):
  x,y,c = [int(i) for i in input().split()]
  buf = A[x-1]+B[y-1]-c
  if buf<min:
    min = buf
print(min)

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

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




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


xyc=[]
for i in range(M):
    x,y,c = map(int, input().split())
    xyc.append((x,y,c))
     
def main():
    mn = sorted(a)[0]+sorted(b)[0]
    for x, y, c in xyc:
        mn = min(mn, a[x-1]+b[y-1] - c)

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

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

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

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

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

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

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 i in range(M)]
ANS=[min(AList)+min(BList)]
i=0
while i<M:
    ANS.append(AList[XYCList[i][0]-1]+BList[XYCList[i][1]-1]-XYCList[i][2])
    i+=1
print(min(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()]
xyc = []
for _ in range(0,M):
    xyc.append([int(x) for x in input().split()])

ans = 0

ans = min(a) + min(b)

coupon = []

for i in range(0,M):
    coupon.append(a[xyc[i][0]-1] + b[xyc[i][1]-1] - xyc[i][2])

ans = min(ans,min(coupon))

print(ans)

Solution (Python):
import bisect,collections,copy,heapq,itertools,math,numpy,string
import sys
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def SS(): return map(str,sys.stdin.readline().rstrip().split())
def II(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())

A,B,M = II()
a = LI()
b = LI()
ticket = [LI() for _ in range(M)]

cost = min(a) + min(b)
costl = [a[t[0]-1] + b[t[1]-1] - t[2] for t in ticket]

print(min(cost,min(costl)))

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

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

for _ in range(m):
    x, y, c = map(int, input().split())
    _a = a_list[x-1]
    _b = b_list[y-1]
    cost = _a + _b - c
    min_cost = min(cost, min_cost)
print(min_cost)

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

discount = []

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

ans_a = float('inf')
ans_b = float('inf')

for e in a:
    ans_a = min(ans_a, e)

for e in b:
    ans_b = min(ans_b, e)

ans = ans_a + ans_b

for x,y,c in discount:
    temp = a[x]+b[y]-c
    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()))

x = []
y = []
c = []
for i in range(m):
	xx, yy, cc = map(int, input().split())
	x.append(xx)
	y.append(yy)
	c.append(cc)


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 = []
Y = []
C = []
for i in range(M):
    x, y, c = map(int, input().split())
    X.append(x)
    Y.append(y)
    C.append(c)

mn = min(a) + min(b)

for i in range(M):
    t = a[X[i]-1] + b[Y[i]-1] - C[i]
    mn = min(t, mn)

print(mn)

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 = 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 = min(A)+min(B)
for xyc in XYC:
    MIN = min(MIN,A[xyc[0]-1]+B[xyc[1]-1]-xyc[2])
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())
    ans = min(ans, a[x - 1] + b[y - 1] - c)
print(ans)

Solution (Python):
def resolve():
    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()]
    zyc = [list(map(int, input().split())) for _ in range(M)]

    minAB = min(a) + min(b)
    for z, y, c in zyc:
        tmp = a[z - 1] + b[y - 1] - c
        minAB = min(minAB, tmp)
    print(minAB)


resolve()

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

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

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

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

ans = min(a) + min (b)

for i in range(m):
    keep = a[c[i][0]-1] + b[c[i][1]-1] - c[i][2]
    if keep < ans:
        ans = keep

print(ans)

Solution (Python):
A,B,M=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=[list(map(int,input().split())) for i in range(M)]
d = 0
e = 0
aa=sorted(a)
bb=sorted(b)

e=aa[0]+bb[0]

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

print(e)

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

ans = []
ans.append(min(A)+min(B))


for i in range(m):
    M = list(map(int,input().split()))
    tmp = A[M[0]-1] + B[M[1]-1] -M[2]
    ans.append(tmp)

print(min(ans))

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


def read():
    _, _, M = map(int, input().strip().split())
    A = list(map(int, input().strip().split()))
    B = list(map(int, input().strip().split()))
    XYC = []
    for i in range(M):
        x, y, c = map(int, input().strip().split())
        XYC.append((x, y, c))
    return A, B, M, XYC


def solve(A, B, M, XYC):
    min_cost = min(A) + min(B)
    for x, y, c in XYC:
        cost = A[x-1] + B[y-1] - c
        min_cost = min(min_cost, cost)
    return min_cost


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))

Solution (Python):
import sys

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

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

print(min(t, sorted(a)[0] + sorted(b)[0]))

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 _ in range(m):
    x,y,c = map(int,input().split())
    if Min > A[x-1]+B[y-1]-c:
        Min=A[x-1]+B[y-1]-c
print(Min)

Solution (Python):
A, B, M = map(int, input().split())
As = list(map(int, input().split()))
Bs = list(map(int, input().split()))
coupons = []
for _ in range(M):
    x, y, c = map(int, input().split())
    coupons.append((x, y, c))

price_min = min(As) + min(Bs)
coupon_min = min([As[x - 1] + Bs[y - 1] - c for (x, y, c) in coupons])

print(min((price_min, coupon_min)))

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

for _ in range(m):
    x, y, c = map(int, input().split())
    x -= 1
    y -= 1
    total = a_list[x] +b_list[y] - c
    money.append(total)
money.append(min(a_list) + min(b_list))
print(min(money))

Solution (Python):

def inp():
    return(int(input()))



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



def instr():
    s = input()
    return(list(s[:len(s)]))



def invr():
    return(map(int, input().split()))


A, B, M = invr()

a = inlist()  
b = inlist()  

C = []
for i in range(M):
    C.append(inlist())

costs_of_using_tickets = [0] * M

for i in range(M):
    ci = C[i]
    costs_of_using_tickets[i] = a[ci[0]-1] + b[ci[1]-1] - ci[2]

cost_of_not_using_tickets = min(a) + min(b)

print(min(cost_of_not_using_tickets, min(costs_of_using_tickets)))

Solution (Python):
from sys import stdin
import math
import re
import queue

input = stdin.readline

MOD = 1000000007
INF = 122337203685477580

def solve():
    A,B,M = map(int, input().split())
    v1 =list(map(int, input().split())) 
    v2 =list(map(int, input().split())) 
    res = INF
    for i in range(M):
        X,Y,C = map(int, input().split())
        res = min(res,v1[X-1] + v2[Y-1] - C)

    res = min(res,min(v1) + min(v2))
    res = max(0,res)
    print(res)


if __name__ == '__main__':
    solve()

Solution (Python):
import math
from collections import deque
from collections import defaultdict


def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()
def factorization(n):
	res = []
	if n%2==0:
		res.append(2)
	for i in range(3,math.floor(n//2)+1,2):
		if n%i==0:
			c = 0
			for j in res:
				if i%j==0:
					c=1
			if c==0:
				res.append(i)
	return res
def fact2(n):
	p = factorization(n)
	res = []
	for i in p:
		c=0
		z=n
		while 1:
			if z%i==0:
				c+=1
				z/=i
			else:
				break
		res.append([i,c])
	return res
def fact(n):
	ans = 1
	m=n
	for _i in range(n-1):
		ans*=m
		m-=1
	return ans
def comb(n,r):
	if n<r:
		return 0
	l = min(r,n-r)
	m=n
	u=1
	for _i in range(l):
		u*=m
		m-=1
	return u//fact(l)
def combmod(n,r,mod):
	return (fact(n)/fact(n-r)*pow(fact(r),mod-2,mod))%mod
def printQueue(q):
	r=copyQueue(q)
	ans=[0]*r.qsize()
	for i in range(r.qsize()-1,-1,-1):
		ans[i] = r.get()
	print(ans)
class UnionFind():
	def __init__(self, n):
		self.n = n
		self.parents = [-1]*n

	def find(self, x): 
		if self.parents[x]<0:
			return x
		else:
			self.parents[x] = self.find(self.parents[x])
			return self.parents[x]

	def union(self,x,y):
		x = self.find(x)
		y = self.find(y)

		if x==y:
			return

		if self.parents[x]>self.parents[y]:
			x,y = y,x

		self.parents[x]+=self.parents[y]
		self.parents[y]=x

	def size(self,x):
		return -1*self.parents[self.find(x)]

	def same(self,x,y):
		return self.find(x)==self.find(y)

	def members(self,x): 
		root = self.find(x)
		return [i for i in range(self.n) if self.find(i)==root]

	def roots(self):
		return [i for i,x in enumerate(self.parents) if x<0]

	def group_count(self):
		return len(self.roots())

	def all_group_members(self):
		return {r: self.members(r) for r in self.roots()} 
def bitArr(n):
	x = 1
	zero = "0"*n
	ans = []
	ans.append([0]*n)
	for i in range(2**n-1):
		ans.append(list(map(lambda x:int(x),list((zero+bin(x)[2:])[-1*n:]))))
		x+=1
	return ans;
def arrsSum(a1,a2):
	for i in range(len(a1)):
		a1[i]+=a2[i]
	return a1
def maxValue(a,b,v):
	v2 = v
	for i in range(v2,-1,-1):
		for j in range(v2//a+1): 
			k = i-a*j
			if k%b==0:
				return i
	return -1
def copyQueue(q):
	nq = queue.Queue()
	n = q.qsize()
	for i in range(n):
		x = q.get()
		q.put(x)
		nq.put(x)
	return nq

a,b,m = readInts()
a_arr = readInts()
b_arr = readInts()
xyc = [[] for i in range(a)]
for i in range(m):
	x,y,c = readInts()
	xyc[x-1].append([y-1,c])

ans = min(a_arr)+min(b_arr)

for i in range(len(xyc)):
	for j in xyc[i]:
		ans = min(ans,a_arr[i]+b_arr[j[0]]-j[1])

print(ans)

Solution (Python):
a,b,m = map(int, input().split())
al = list(map(int, input().split()))
bl = list(map(int, input().split()))
xyc = [list(map(int, input().split())) for i in range(m)]
ans = min(al)+min(bl)
for l in xyc:
    p = al[l[0]-1] + bl[l[1]-1] -l[2]
    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()))
asorted = sorted(a)
bsorted = sorted(b)
cost = {asorted[0]+bsorted[0]}

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

Solution (Python):
import sys

readline = sys.stdin.readline

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


if __name__ == "__main__":
    main()

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

ans=min(al)+min(bl)
for i in range(m):
    tmp=0
    tmp=al[xyc[i][0]-1]+bl[xyc[i][1]-1]-xyc[i][2]
    ans=min(ans,tmp)
print(ans)

Solution (Python):
A,B,M = [int(hoge) for hoge in input().split()]
A = [int(hoge) for hoge in input().split()]
B = [int(hoge) for hoge in input().split()]
ans = min(A) + min(B)
for i in range(M):
    x,y,c = [int(hoge) for hoge in 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)]
ans=min(a)+min(b)
for i in range(M):
    tmp = a[xyc[i][0]-1]+b[xyc[i][1]-1]-xyc[i][2]
    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()))

ans = min(a) + min(b)
for _ 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
    else:
        pass
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())
    x -= 1
    y -= 1
    ans = min(ans, a[x] + b[y] - c)

print(ans)

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

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

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

result = min(s, c_min)
print(result)

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

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

if (min(a) + min(b)) < ans:
    ans = min(a) + min(b)

print(ans)

Solution (Python):
import sys

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

a = list(map(int, sys.stdin.readline().rsplit()))
b = list(map(int, sys.stdin.readline().rsplit()))

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

Solution (Python):
a, b, m = list(map(int, input().split()))
refrigerator_list = list(map(int, input().split()))
microwave_list = list(map(int, input().split()))
coupon_list = list()
for _ in range(m):
    coupon_list.append(list(map(int, input().split())))

ans = min(refrigerator_list) + min(microwave_list)
for coupon in coupon_list:
    ans = min(refrigerator_list[coupon[0] - 1] + microwave_list[coupon[1] - 1] - coupon[2], ans)

print(ans)

Solution (Python):
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = [list(map(int, input().split())) for _ in range(M)]
buy = [min(a)+min(b)]
for i in range(M):
  C = a[c[i][0]-1]+b[c[i][1]-1]-c[i][2]
  buy.append(C)
print(min(buy))

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

M = min(A)+min(B)

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

print(M)

Solution (Python):
from collections import defaultdict
import numpy as np

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

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

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

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

print(mi)

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

X=list()
Y=list()
C=list()
for i in range(M):
  x,y,c=map(int,input().split())
  X.append(x)
  Y.append(y)
  C.append(c)
ans=list()
for i in range(M):
  xx=int(X[i])-1
  yy=int(Y[i])-1
  cc=int(C[i])
  num=int(A[xx])+int(B[yy])-cc
  ans.append(num)
Ans=int(min(ans))
print(min(ab,Ans))

Solution (Python):
import sys

input = sys.stdin.readline

def main():
    ans = 10**5 * 2
    A, B, M = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    ans = sorted(a)[0] + sorted(b)[0]
    
    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)

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

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

print(m)

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

ans = min(a_l) + min(b_l)
for x, y, c in xyc:
    ans = min(ans, a_l[x-1]+b_l[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()))

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

    pr.append(a[X[0]-1] + b[X[1]-1] - X[2])

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

Solution (Python):
def resolve():
    a, b, m = map(int, input().split())
    a_s = [int(i) for i in input().split()]
    b_s = [int(i) for i in input().split()]

    min_cost = min(a_s) + min(b_s)
    for _ in range(m):
        a_i, b_i, c_i = map(int, input().split())
        cost = a_s[a_i-1] + b_s[b_i-1] - c_i
        if cost < min_cost:
            min_cost = cost

    print(min_cost)


resolve()

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)]
a1=sorted(a)
b1=sorted(b)
price=a1[0]+b1[0]
ans=float('inf')
for i in range(m):
    x=a[xyc[i][0]-1]+b[xyc[i][1]-1]-xyc[i][2]
    if x<ans:
        ans=x
print(min(price,ans))

Solution (Python):



A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
coupon = [list(map(int, input().split())) for _ in range(M)]
a_min, b_min = min(a), min(b)
discount = []
for i in range(M):
    discount.append(a[coupon[i][0] - 1] + b[coupon[i][1] - 1] - coupon[i][2])
if a_min + b_min < min(discount):
    print(a_min + b_min)
else:
    print(min(discount))

Solution (Python):
a, b, m = map(int, input().split())
lsa = list(map(int, input().split()))
lsb = list(map(int, input().split()))
cost = min(lsa) + min(lsb)
for i in range(m):
    x, y, c = map(int, input().split())
    cost2 = lsa[x - 1] + lsb[y - 1] - c
    if cost2 < cost:
        cost = cost2

print(cost)

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

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

print(ans)

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

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

A, B, M = MAP()
a = LIST()
b = LIST()
xyc = [LIST() 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)