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 re
import math
import itertools
from copy import deepcopy
import random
from heapq import heappop,heappush
import time
import os
import queue
import sys
import datetime
from functools import lru_cache
readline=sys.stdin.readline
sys.setrecursionlimit(2000)

alphabet="abcdefghijklmnopqrstuvwxyz"
mod=int(10**9+7)
inf=int(10**20)
week=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]
def yn(b):
    if b:
        print("yes")
    else:
        print("no")
def Yn(b):
    if b:
        print("Yes")
    else:
        print("No")
def YN(b):
    if b:
        print("YES")
    else:
        print("NO")
class union_find():
    def __init__(self,n):
        self.n=n
        self.P=[a for a in range(N)]
        self.rank=[0]*n
 
    def find(self,x):
        if(x!=self.P[x]):self.P[x]=self.find(self.P[x])
        return self.P[x]
 
    def same(self,x,y):
        return self.find(x)==self.find(y)
 
    def link(self,x,y):
        if self.rank[x]<self.rank[y]:
            self.P[x]=y
        elif self.rank[y]<self.rank[x]:
            self.P[y]=x
        else:
            self.P[x]=y
            self.rank[y]+=1
 
    def unite(self,x,y):
        self.link(self.find(x),self.find(y))
 
    def size(self):
        S=set()
        for a in range(self.n):
            S.add(self.find(a))
        return len(S)
def is_power(a,b):
    now=b
    while now<a:
        now*=b
    if now==a:return True
    else:return False
def bin_(num,size):
    A=[0]*size
    for a in range(size):
        if (num>>(size-a-1))&1==1:
            A[a]=1
        else:
            A[a]=0
    return A
def facs(n,mod_=0):
    A=[1]*(n+1)
    for a in range(2,len(A)):
        A[a]=A[a-1]*a
        if(mod_>0):A[a]%=mod_
    return A
def comb(n,r,mod_,fac):
    if(n-r<0):return 0
    return (fac[n]*pow(fac[n-r],mod_-2,mod_)*pow(fac[r],mod_-2,mod_))%mod_
def next_comb(num,size):
    x=num&(-num)
    y=num+x
    z=num&(~y)
    z//=x
    z=z>>1
    num=(y|z)
    if(num>=(1<<size)):return False
    else:
        return num
def get_primes(n,type="int"):
    A=[True]*(n+1)
    A[0]=False
    A[1]=False
    for a in range(2,n+1):
        if A[a]:
            for b in range(a*2,n+1,a):
                A[b]=False
    if(type=="bool"):return A
    B=[]
    for a in range(n+1):
        if(A[a]):B.append(a)
    return B
def is_prime(num):
    if(num<=2):return False
    i=2
    while i*i<=num:
       if(num%i==0):return False
       i+=1
    return True
def ifelse(a,b,c):
    if a:return b
    else:return  c
def join(A,c=" "):
    n=len(A)
    A=list(map(str,A))
    s=""
    for a in range(n):
        s+=A[a]
        if(a<n-1):s+=c
    return s
def factorize(n,type_="dict"):
    b = 2
    list_ = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            list_.append(b)
        b+=1
    if n > 1:list_.append(n)
    if type_=="dict":
        dic={}
        for a in list_:
            if a in dic:
                dic[a]+=1
            else:
                dic[a]=1
        return dic
    elif type_=="list":
        return list_
    else:
        return None
def floor_(n,x=1):
    return x*(n//x)
def ceil_(n,x=1):
    return x*((n+x-1)//x)


import re
import math
import itertools
from copy import deepcopy
import random
from heapq import heappop,heappush
import time
import os
import queue
import sys
import datetime
from functools import lru_cache
readline=sys.stdin.readline
sys.setrecursionlimit(2000)

alphabet="abcdefghijklmnopqrstuvwxyz"
mod=int(10**9+7)
inf=int(10**20)
def yn(b):
    if b:
        print("yes")
    else:
        print("no")
def Yn(b):
    if b:
        print("Yes")
    else:
        print("No")
def YN(b):
    if b:
        print("YES")
    else:
        print("NO")
class union_find():
    def __init__(self,n):
        self.n=n
        self.P=[a for a in range(N)]
        self.rank=[0]*n
 
    def find(self,x):
        if(x!=self.P[x]):self.P[x]=self.find(self.P[x])
        return self.P[x]
 
    def same(self,x,y):
        return self.find(x)==self.find(y)
 
    def link(self,x,y):
        if self.rank[x]<self.rank[y]:
            self.P[x]=y
        elif self.rank[y]<self.rank[x]:
            self.P[y]=x
        else:
            self.P[x]=y
            self.rank[y]+=1
 
    def unite(self,x,y):
        self.link(self.find(x),self.find(y))
 
    def size(self):
        S=set()
        for a in range(self.n):
            S.add(self.find(a))
        return len(S)
def is_power(a,b):
    now=b
    while now<a:
        now*=b
    if now==a:return True
    else:return False
def bin_(num,size):
    A=[0]*size
    for a in range(size):
        if (num>>(size-a-1))&1==1:
            A[a]=1
        else:
            A[a]=0
    return A
def get_facs(n,mod_=0):
    A=[1]*(n+1)
    for a in range(2,len(A)):
        A[a]=A[a-1]*a
        if(mod>0):A[a]%=mod_
    return A
def comb(n,r,mod,fac):
    if(n-r<0):return 0
    return (fac[n]*pow(fac[n-r],mod-2,mod)*pow(fac[r],mod-2,mod))%mod
def next_comb(num,size):
    x=num&(-num)
    y=num+x
    z=num&(~y)
    z//=x
    z=z>>1
    num=(y|z)
    if(num>=(1<<size)):return False
    else:
        return num
def get_primes(n,type="int"):
    A=[True]*(n+1)
    A[0]=False
    A[1]=False
    for a in range(2,n+1):
        if A[a]:
            for b in range(a*2,n+1,a):
                A[b]=False
    if(type=="bool"):return A
    B=[]
    for a in range(n+1):
        if(A[a]):B.append(a)
    return B
def is_prime(num):
    if(num<=2):return False
    i=2
    while i*i<=num:
       if(num%i==0):return False
       i+=1
    return True
def ifelse(a,b,c):
    if a:return b
    else:return  c
def join(A,c=" "):
    n=len(A)
    A=list(map(str,A))
    s=""
    for a in range(n):
        s+=A[a]
        if(a<n-1):s+=c
    return s
def factorize(n,type_="dict"):
    b = 2
    list_ = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            list_.append(b)
        b+=1
    if n > 1:list_.append(n)
    if type_=="dict":
        dic={}
        for a in list_:
            if a in dic:
                dic[a]+=1
            else:
                dic[a]=1
        return dic
    elif type_=="list":
        return list_
    else:
        return None
def floor_(n,x=1):
    return x*(n//x)
def ceil_(n,x=1):
    return x*((n+x-1)//x)

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


main()

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

for i in range(M):
    tmp = list(map(int, input().split()))
    checkout = min(checkout, a[tmp[0]-1] + b[tmp[1]-1] - tmp[2])

print(checkout)

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

while True:
  try:
    tmp1,tmp2,tmp3 = map(int,input().split())
    x.append(tmp1)
    y.append(tmp2)
    c.append(tmp3)
  except:
    break
    
not_use = min(a) + min(b)

ansList = [not_use]
for i in range(M):
  tmp = a[x[i]-1] + b[y[i]-1] - c[i]
  ansList.append(tmp)
ans = min(ansList)
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()]
xyc = [[int(i) for i in input().split()] for _ in range(M)]
ans = min(a) + min(b)
for z in xyc:
    x, y, c = z
    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()))
Z = [list(map(int, input().split())) for i in range(M)]

li = []
for z in Z:
    li.append(a[z[0]-1]+b[z[1]-1]-z[2])
li.append(min(a)+min(b))
print(min(li))

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

Solution (Python):
A, B, M = map(int, input().split())
A_list = list(map(int, input().split()))
B_list = list(map(int, input().split()))
M_list = []
for _ in range(M):
  M_list.append(list(map(int, input().split())))

Min_1 = min(A_list) + min(B_list)
Min_2 = []
for m in M_list:
  Min_2.append(A_list[m[0] - 1] + B_list[m[1] - 1] - m[2])
if Min_1 < min(Min_2):
  print(Min_1)
else:
  print(min(Min_2))

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

Solution (Python):
from sys import stdin
A, B, M = [int(_) for _ in stdin.readline().rstrip().split()]
A = [int(_) for _ in stdin.readline().rstrip().split()]
B = [int(_) for _ in stdin.readline().rstrip().split()]
XYC = [list(map(int, stdin.readline().rstrip().split())) for _ in range(M)]
ans = [min(A)+min(B)]
for x, y, c in XYC:
  ans.append(A[x-1]+B[y-1]-c)
print(min(ans))

Solution (Python):
import numpy as np
tmp = list(map(int, input().split(' ')))
A = tmp[0]
B = tmp[1]
m = tmp[2]
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):
    ans = min(a[xyc[i][0]-1]+b[xyc[i][1]-1]-xyc[i][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 = [tuple(map(int,input().split())) for i in range(m)]
p = [min(a)+min(b)]
for t in c:
    p.append(a[t[0]-1]+b[t[1]-1]-t[2])
print(min(p))

Solution (Python):
a,b,m = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = [tuple(map(int,input().split())) for i in range(m)]
p = min(a)+min(b)
for t in c:
    p = min(p,a[t[0]-1]+b[t[1]-1]-t[2])
print(p)

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

P = list(map(int, input().split()))
Q = list(map(int, input().split()))

res = min(P) + min(Q)

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

    res = min(res, P[x] + Q[y] - c)

print(res)

Solution (Python):












A,B,M = map(int,input().split())
arrA = list(map(int,input().split()))
arrB = list(map(int,input().split()))
times = M
table = []
for _ in range(times):
    x,y,c = list(map(int,input().split())) 
    table.append(arrA[x-1]+arrB[y-1]-c)

simplelow = min(arrA)+min(arrB)
ans = min(simplelow,min(table))

print(ans)

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

Solution (Python):
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(tuple(map(int, input().split())))

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

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

    tmp = a[x-1] + b[y-1] - c

    if tmp < minv:
        minv = tmp

print(minv)

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

ans=min(a)+min(b)

for k in range(M):
    i=t[k][0]
    j=t[k][1]
    
    Y=a[i-1]+b[j-1]-t[k][2]
    if Y<=ans:
        ans=Y

print(ans)

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

ans=min(a)+min(b)

for k in range(M):
    i=t[k][0]
    j=t[k][1]
    
    Y=a[i-1]+b[j-1]-t[k][2]
    if Y<=ans:
        ans=Y

print(ans)

Solution (Python):

if False:
    K,X=map(int,input().split())
    print('Yes' if 500*K>=X else 'No')


if False:
    N=int(input())
    S=input()
    print(S.count('ABC'))


if False:
    import itertools
    N=int(input())
    dic=list(itertools.permutations(list(range(1,N+1))))
    
    P=tuple(int(i) for i in input().split())
    Q=tuple(int(i) for i in input().split())

    print(abs(dic.index(P)-dic.index(Q)))


if True:
    A,B,M=map(int,input().split())
    a=[int(i) for i in input().split()]
    b=[int(i) for i in input().split()]
    M=[tuple(int(j) for j in input().split()) for i in range(M)]
    ans=min(a)+min(b)
    for x,y,c in M:
        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, y, c = [], [], []
for _ in range(M):
    xi, yi, ci = map(int, input().split())
    x.append(xi)
    y.append(yi)
    c.append(ci)









cost1 = min(a) + min(b)
cost = [cost1]

for j in range(M):
    xj, yj, cj = x[j], y[j], c[j]
    costj = a[xj - 1] + b[yj - 1] - cj
    cost.append(costj)

print(min(cost))

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():

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

    ans=min(A)+min(B)

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


resolve()

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

print(result)

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 myAnswer(a:list,b:list,XYC:list) -> int:
   ans = min(a) + min(b)
   for x,y,c in XYC:
      total = a[x-1] + b[y-1] - c
      ans = min(total,ans)
   return ans



def modelAnswer():
   tmp=1
def main():
   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())))
   print(myAnswer(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()))

price=[0]*(M+1)

price[0] = min(a)+min(b)

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

print(min(price))

Solution (Python):
NA, NB, NM = (int(x) for x in input().split())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
M = [[int(x) for x in input().split()] for i in range(NM)]
res = min(A) + min(B)
for i in range(NM):
  x, y, c = M[i]
  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()))
card = [list(map(int, input().split())) for _ in range(M)]

min_price = min(a) + min(b)

for C in card:
    x, y, c = C
    price = a[x - 1] + b[y - 1] - c
    if price < min_price:
        min_price = price
print(min_price)

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

XYC = []
for _ in range(M):
    XYC.append([int(i) for i in input().split(' ')])

min_a , min_b = min(AA),min(BB)
min_ab = min_a + min_b

for x,y,c in XYC:
    cost = AA[x-1] + BB[y-1] - c
    min_ab = min(cost,min_ab)

print(min_ab)

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

small = min(a) + min(b)

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

print(small)

Solution (Python):
import sys
import heapq
import re
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from fractions import gcd
from math import factorial, sqrt
from functools import lru_cache, reduce
INF = 1 << 60
mod = 1000000007
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline


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 -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 __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


def dijkstra_heap(s, edge, n):
    
    d = [10**20] * n
    used = [True] * n 
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d


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


def lcm(x, y):
    return (x * y) // gcd(x, y)


def lcm_list(numbers):
    return reduce(lcm, numbers, 1)


def gcd_list(numbers):
    return reduce(gcd, numbers)


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(' ')))
cost = min(A) + min(B)
i = 0
while i < m:
    x,y,c = map(int,input().split(' '))
    cost0 = A[x-1]+B[y-1]-c
    if cost0 < cost:
        cost = cost0
    i += 1
print(cost)

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

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

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

normal = min(refrigerator) + min(oven)
ans = normal

tmp = 0


for i in range(m):
  tmp = refrigerator[coupon[i][0]-1]+oven[coupon[i][1]-1]-coupon[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()))
x_y_c = [list(map(int, input().split())) for i in range(M)]

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

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

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

min_sum = min(A) + min(B)

M = []
for i in range(m):
      an, bn, diff = list(map(int, input().split()))
      M.append(A[an - 1] + B[bn - 1] - diff)

diff_min = min(M)
print(min_sum if min_sum < diff_min else diff_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 = list(map(int,input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
m = [list(map(int, input().split())) for _ in range(M)]


min_val = min(a) + min(b)

for ai, bi, ci in m:
    val = a[ai-1] + b[bi-1] - ci
    if min_val > val:
        min_val = val
print(min_val)

Solution (Python):

A, B, M = list(map(int,input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
m = [list(map(int, input().split())) for _ in range(M)]


min_val = min(a) + min(b)

for ai, bi, ci in m:
    val = a[ai-1] +b[bi-1] -ci
    if min_val > val:
        min_val = val
print(min_val)

Solution (Python):
def main():
    _, _, 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):
A,B,M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
m=[]
for i in range(M):
    array = list(map(int, input().strip().split()))
    m.append(array)

def hitachi02(a,b,m):
    results=[]
    cal01=min(a)+min(b)
    for k in range(len(m)):
        results.append(a[m[k][0]-1]+b[m[k][1]-1]-m[k][2])
    cal02=min(results)
    if cal01>=cal02:
        return cal02
    else:
        return cal01

result=hitachi02(a,b,m)
print(result)

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

Solution (Python):
''' ===========================================
from collections import deque
    appendleft() = push_front(), append = push_back()
    popfleft() = pop_front(), pop() = pop_back()
import heapq 
=========================================== '''

import sys
import collections
sys.setrecursionlimit(10**6)

class gv:
    A, B, M = [0,0,0]
    renzi = []
    reizo = []
    
def build():
    gv.A, gv.B, gv.M = map(int, sys.stdin.readline().split(' '))
    *gv.renzi, = map(int, input().split())
    *gv.reizo, = map(int, input().split())

def solve():
    ans = min(gv.renzi) + min(gv.reizo)
    
    for i in range(gv.M):
        rx, ry, rc = map(int, input().split())
        
        ans_buf = gv.renzi[rx -1] + gv.reizo[ry -1] - rc
        ans = min(ans, ans_buf)
    
    print(ans)

if __name__ == '__main__':
    build()
    solve()

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

Solution (Python):
import pprint

def buy():

    num_refrigerator, num_microwave, num_coupon = map(
        lambda x : int(x), input().split(" ")
    )

    price_list_refrigerator = list(map(lambda x : int(x), input().split(" ")))
    price_list_microwave = list(map(lambda x : int(x), input().split(" ")))

    coupon_list = []
    for _ in range(num_coupon):
        coupon_list.append(list(map(lambda x : int(x), input().split(" "))))

    
    least_price = min(price_list_refrigerator) + min(price_list_microwave)

    for product in coupon_list:
        use_coupon_price = (price_list_refrigerator[product[0] - 1]
                        + price_list_microwave[product[1] - 1]
                        - product[2])
        if(least_price > use_coupon_price):
            least_price = use_coupon_price

    print(least_price)


if __name__ == "__main__":
    buy()

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

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

ans = min(a_li) + min(b_li)

for i in range(m):
    a_num = sum_li[i][0]
    b_num = sum_li[i][1]
    waribiki = sum_li[i][2]
    
    a_place = a_li[a_num-1]
    b_place = b_li[b_num-1]
    
    ans = min(ans, a_place + b_place - waribiki)
    
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):
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))
a,b,m = iim()
A = iil()
B = iil()
ans = min(A)+min(B)

for i in range(m):
    x,y,c = iim()
    ans = min(ans,A[x-1]+B[y-1]-c)
print(ans)

Solution (Python):
a,b,m=map(int,input().split())
a_prices=[int(i) for i in input().split()]
b_prices=[int(i) for i in input().split()]
a_min=min(a_prices)
b_min=min(b_prices)
a_add_b=a_min+b_min
for i in range(m):
    x,y,c=map(int,input().split())
    if a_prices[x-1]+b_prices[y-1]-c<a_add_b:
        a_add_b=a_prices[x-1]+b_prices[y-1]-c
print(a_add_b)

Solution (Python):
a,b,m=map(int,input().split())
a_prices=[int(i) for i in input().split()]
b_prices=[int(i) for i in input().split()]
a_min=min(a_prices)
b_min=min(b_prices)
a_add_b=a_min+b_min
for i in range(m):
    x,y,c=map(int,input().split())
    if a_prices[x-1]+b_prices[y-1]-c<a_add_b:
        a_add_b=a_prices[x-1]+b_prices[y-1]-c
print(a_add_b)

Solution (Python):
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,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 operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 

def ii(): return int(sys.stdin.readline().rstrip()) 
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) 
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]

def ss(): return sys.stdin.readline().rstrip() 
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) 
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]





a,b,m=mii()
arra=limii()
arrb=limii()

ans=min(arra)+min(arrb)

for i in range(m):
    x,y,c=mii()
    ans = min(ans, arra[x-1]+arrb[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())
price = min(a) + min(b)
for j in range(M):
    cprice = a[x[j]-1] + b[y[j]-1] - c[j]
    if cprice < price:
        price = cprice
print(price)

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

Solution (Python):
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):
    tmp = a[discount[i][0]-1] + b[discount[i][1]-1] - discount[i][2]
    if  tmp < ans:
        ans = tmp

print(ans)

Solution (Python):

from decimal import *
from itertools import permutations, combinations,combinations_with_replacement,product

s = input().split()
t = [int(p) for p in s]

A = t[0]
B = t[1]
M = t[2]

s = input().split()
t = [int(p) for p in s]

a = t

s = input().split()
t = [int(p) for p in s]

b = t

discount = []
for i in range(M):
    s = input().split()
    t = [int(p) for p in s]
    discount.append(t)


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

for i in range(len(discount)):
    price.append( a[discount[i][0] - 1] + b[discount[i][1] - 1] - discount[i][2])




print(min(price))

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()]
l = []
for i in range(M):
    l.append([int(i) for i in input().split()])

cand = [min(a)+min(b)]
for i in range(M):
    if l[i][0]-1<A and l[i][1]-1<B:
        cand.append(a[l[i][0]-1]+b[l[i][1]-1]-l[i][2])

print(min(cand))