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 sys
sys.setrecursionlimit(10 ** 7)

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

AS = list(map(int, input().split()))
BS = list(map(int, input().split()))

xyc = [[int(x) for x in input().split()] for _ in range(M)]

ans = min(AS) + min(BS)

for x, y, c in xyc:
    r = AS[x - 1] + BS[y - 1] - c
    ans = min(ans, r)

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

P = [[int(i) for i in input().split()] for _ in range(M)]

ans = min(a) + min(b)

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

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

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

Solution (Python):
def main():
    
    
    
    
    
    
    
    
    
    
    
    
    
    

    A, B, 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()))

ans = min(a) + min(b)

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

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

    ans = min(price, ans)

print(ans)

Solution (Python):
if __name__ == '__main__':
    from sys import stdin
    input = stdin.readline

    a, b, m = map(int, input().split())
    aa = list(map(int, input().split()))
    bb = list(map(int, input().split()))
    min_ab = min(aa) + min(bb)
    for _ in range(m):
        x, y, c = map(int, input().split())
        now = aa[x-1] + bb[y-1] - c
        if min_ab > now:
            min_ab = now
    print(min_ab)

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

Solution (Python):
a,b,m=map(int,input().split())
la =list(map(int,input().split()))
lb =list(map(int,input().split()))
ans = min(la)+min(lb)
for i in range(m):
  aa,bb,cc =map(int,input().split())
  ans =min(ans,la[aa-1]+lb[bb-1]-cc)
print(ans)

Solution (Python):
a, b, m = [int(v) for v in input().split()]
alist = [int(v) for v in input().split()]
blist = [int(v) for v in input().split()]
mlist = [tuple(int(v) for v in input().split()) for _ in range(m)]
mlist = [(ai - 1, bi - 1, c) for ai, bi, c in mlist]

cost = min(alist) + min(blist)
for x, y, c in mlist:
    lc = alist[x] + blist[y] - c
    if lc < cost:
        cost = lc

print(cost)

Solution (Python):
a, b, m = map(int, input().split())
data = list(map(int, input().split()))
datb = list(map(int, input().split()))
res = 999999999999
for i in range(m):
    x, y, c = map(int, input().split())
    t = data[x - 1] + datb [y - 1] - c
    res = min(res, t)
data.sort()
datb.sort()
res = min(res, data[0] + datb[0])
print(res)

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

ans=[]

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

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

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

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

nouse = min(a) + min(b)
ans = []
ans.append(nouse)
for x in X:
    re, de, c = x
    ans.append(a[re-1] + b[de-1] - c)

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

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

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

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

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
A, B, M = [int(x) for x in input().strip().split()]
a = [int(x) for x in input().strip().split()]
b = [int(x) for x in input().strip().split()]
ans = min(a) + min(b)
for m in range(M):
    x, y, c = [int(x) for x in input().strip().split()]
    ans = min(ans, a[x-1]+b[y-1]-c)

print(ans)

Solution (Python):
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**9)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

a,b,m = na()

aa = na()
bb = na()

ans = min(aa)+min(bb)

for i in range(m):
    x,y,c = na()
    ans = min(ans,aa[x-1]+bb[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):
    x, y, c = map(int, input().split())
    X.append(x)
    Y.append(y)
    C.append(c)
 
ans = min(A) + min(B)
for i in range(m):
    tot = A[X[i]-1] +B[Y[i]-1] - C[i]
    ans = min(tot, ans)
print(ans)

Solution (Python):
a,b,m = map(int,input().split())
l = list(map(int,input().split()))
d = list(map(int,input().split()))
ans = min(l)+min(d)
for i in range(m):
  x,y,c = map(int,input().split())
  p = l[x-1]+d[y-1]-c
  if p < ans:
    ans = p
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()))
xyc = [list(map(int, input().split())) for _ in range(M)]
res = [min(a)+min(b)]
for x,y,c in xyc:
    res.append(a[x-1]+b[y-1]-c)
print(min(res))

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

ans = min(a) + min(b)

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

print(ans)

Solution (Python):
import sys
from math import ceil, floor
from collections import deque, Counter, defaultdict
from fractions import gcd
input = lambda: sys.stdin.readline().rstrip()

def eprint(s):
    sys.stderr.write('DEBUG: {}'.format(s))
    return

def main():
    a,b,m = map(int, input().split())
    As = list(map(int, input().split()))
    Bs = list(map(int, input().split()))
    xycs = [list(map(int, input().split())) for i in range(m)]

    
    nin = 10**9
    for i in range(m):
        if As[xycs[i][0]-1] + Bs[xycs[i][1]-1] - xycs[i][2] <= nin:
            nin = As[xycs[i][0]-1] + Bs[xycs[i][1]-1] - xycs[i][2]
    
    print(min(min(As) + min(Bs), nin))
    return

if __name__ == '__main__':
    main()

Solution (Python):
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

A, B, M = lr()
R = lr()
D = lr()
answer = min(R) + min(D)
for _ in range(M):
    x, y, c = lr()
    x -= 1; y -= 1
    temp = R[x] + D[y] - c
    if temp < answer:
        answer = temp

print(answer)

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 i, (xi, yi, ci) in enumerate(xyc):
    ans = min(ans, max(0, a[xi - 1] + b[yi - 1] - ci))

print(ans)

Solution (Python):
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")


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


if __name__ == '__main__':
    main()

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

NA,NB,M = map(int,readline().split())
A = list(map(int,readline().split()))
B = list(map(int,readline().split()))
m = map(int,read().split())
XYC = list(zip(m,m,m))

def gen_cand():
    yield min(A) + min(B)
    for x,y,c in XYC:
        yield A[x-1] + B[y-1] - c

answer = min(gen_cand())
print(answer)

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

ans = min(refs) + min(mcws)

for i in range(m):
	ans = min(ans, refs[coupons[i][0] - 1] + mcws[coupons[i][1] - 1] - coupons[i][2])

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

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

vmin = min(A) + min(B)
for i in range(m):
    v = A[W[i][0]-1] + B[W[i][1]-1] - W[i][2]
    vmin = min(vmin, v)

print(vmin)

Solution (Python):
import numpy as np


def main():
    a, b, m = map(int, input().split())
    a_c = np.array(list(map(int, input().split())), dtype=int)
    b_c = np.array(list(map(int, input().split())), dtype=int)
    discount = [tuple(map(int, input().split())) for _ in range(m)]
    answer = min(a_c) + min(b_c)
    for d in discount:
        answer = min(answer, a_c[d[0] - 1] + b_c[d[1] - 1] - d[2])
    print(answer)


if __name__ == '__main__':
    main()

Solution (Python):
import sys
from collections import defaultdict, Counter, deque
from itertools import accumulate, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right, bisect
from heapq import heappop, heappush
from fractions import gcd
from math import ceil, floor, sqrt, cos, sin, pi
from copy import deepcopy




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

if __name__ == '__main__':
    main()

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

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

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

if __name__ == '__main__':
    main()

Solution (Python):
N, M, K = map(int, input().split())
X = list(map(int, input().split()))
Y = list(map(int, input().split()))
rs = [sorted(X)[0]+sorted(X)[0]]
for _ in range(K):
    a, b, c = map(int, input().split())
    rs.append(X[a-1]+Y[b-1]-c)

rs.sort()
print(rs[0])

Solution (Python):
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=998244353
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  a,b,m=LI()
  la=LI()
  lb=LI()
  l=[LI() for _ in range(m)]

  ans=min(la)+min(lb)
  for x,y,c in l:
    x-=1
    y-=1
    _ans=la[x]+lb[y]-c
    ans=min(ans,_ans)

  return ans


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

candidate = [min(A)+min(B)]

for _ in range(m):
    x, y, c = map(int, input().split())
    cost = A[x-1] + B[y-1] - c
    candidate.append(cost)

print(min(candidate))

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

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

ans = min(a_s) + min(b_s)
for tmp in xyc:
    x,y,c = tmp
    ans = min(ans, a_s[x-1] + b_s[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()))
l = [list(map(int,input().split())) for _ in range(M)]
ans = min(a)+min(b)
for i in l:
    ans = min(ans,a[i[0]-1]+b[i[1]-1]-i[2])
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)
    coupon = [list(map(int,input().split())) for _ in range(M)]
    for i in range(M):
        tmp = a[coupon[i][0]-1] + b[coupon[i][1]-1] - coupon[i][2]
        ans = min(tmp,ans)
    print(ans)

if __name__ == '__main__':
    main()

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

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

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

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 = []
y = []
c = []
setmin = 1001001001001
for _ in range(M):
    xi, yi, ci = map(int, input().split())
    x.append(xi)
    y.append(yi)
    c.append(ci)
    discountprice = a[xi-1] + b[yi-1] - ci
    if discountprice < setmin:
        setmin = discountprice
print(min(min(a)+min(b), setmin))

Solution (Python):
from __future__ import division, print_function

''' Hey stalker :) '''
INF = 10 ** 10
TEST_CASES = False


def main():
    a,b,m = get_list()
    ref = get_list()
    micro = get_list()
    res = min(ref) + min(micro)
    for _ in range(m):
        i,j,dis = get_list()
        res = min(res, ref[i-1]+micro[j-1]-dis)
    print(res)

''' FastIO Footer by @c1729 and other contributors '''
import os
import sys
from bisect import bisect_left, bisect_right
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip
BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)



input = lambda: sys.stdin.readline().rstrip("\r\n")
get_int = lambda: int(input())
get_list = lambda: list(map(int, input().split()))
if __name__ == "__main__":
    if TEST_CASES:
        [main() for _ in range(int(input()))]
    else:
        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):

A,B,M=map(int,input().split())
Al=list(map(int,input().split()))
Bl=list(map(int,input().split()))
C=[]
for i in range(M):
    C.append(list(map(int,input().split())))

ans=min(Al)+min(Bl)

for i in range(M):
    ans=min(ans,Al[C[i][0]-1]+Bl[C[i][1]-1]-C[i][2])

print(ans)

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

Solution (Python):
def solve():
    
    mn = float('inf')
    A, B, M = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    a_min = sorted(a)[0]
    b_min = sorted(b)[0]
    
    for i in range(M):
        x, y, c = map(int, input().split())
        mn = min(a[x-1] + b[y-1] - c, mn)
    
    print(min(mn, a_min + b_min))


if __name__ == '__main__':
    solve()

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

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

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())
    tmp = AA[x-1]+BB[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()))

ans = float('inf')

for _ in range(m):
  x,y,c = map(int,input().split())
  ans = min(A[x-1] + B[y-1] - c,ans)
  
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()))
las=sorted(la)
lbs=sorted(lb)
mini=las[0]+lbs[0]
for i in range(m):
  p,q,r=list(map(int,input().split()))
  mini=min(mini,la[p-1]+lb[q-1]-r)
print(mini)

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

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

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

a_price =  list(map(int, input().split()))
b_price =  list(map(int, input().split()))

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

ans = min(a_price) + min(b_price)

for i in waribiki:
    temp = a_price[i[0]-1] + b_price[i[1]-1] - i[2]
    if temp < ans:
        ans = temp

print(ans)

Solution (Python):
import math
import queue
A,B,M = list(map(int,input().split(" ")))
As = list(map(int,input().split(" ")))
Bs = list(map(int,input().split(" ")))
xycs  =[list(map(int,input().split(" "))) for _ in range(M)]
ans = min(As) + min(Bs)
for temp in xycs:
    x,y,c = temp
    ans = min(ans,As[x-1] + Bs[y-1] - c)
print(ans)

Solution (Python):
a, b, m = map(int,input().split())
alist = list(map(int, input().split()))
blist = list(map(int, input().split()))
saisho=min(alist)+min(blist)
for i in range(m):
    x, y, c = map(int,input().split())
    now=alist[x-1]+blist[y-1]-c
    if now<=saisho:
        saisho=now

print(saisho)

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

import sys
sys.setrecursionlimit(10000000)
INF = 1<<32


def solve(A: int, B: int, M: int, a: "List[int]", b: "List[int]", x: "List[int]", y: "List[int]", c: "List[int]"):
    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)
    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):
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 i in range(m):
    ans=min(a[xyc[i][0]-1]+b[xyc[i][1]-1]-xyc[i][2],ans)
  print(ans)
if __name__ == '__main__':
    main()

Solution (Python):
[a,b,m] = [int(i) for i in input().split()]
a_p = [int(i) for i in input().split()]
b_p = [int(i) for i in input().split()]
ans = 10**9+7
for i in range(m):
    [x,y,c] = [int(i) for i in input().split()]
    tmp = a_p[x-1] + b_p[y-1] - c
    if tmp < ans:
        ans = tmp

print(min(ans,min(a_p)+min(b_p)))

Solution (Python):
import sys
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

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

ans = min(a) + min(b)

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

print(ans)

Solution (Python):
A, B, M = map(int, input().split())
aList = list(map(int, input().split()))
bList = list(map(int, input().split()))
ans = sorted(aList)[0] + sorted(bList)[0]
for i in range(M):
    x, y, c = map(int, input().split())
    p = aList[x-1] + bList[y-1] - c
    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()))
xyc = [list(map(int,input().split())) for i in range(m)]

ans = min(a) + min(b)
for i in range(m):
    ans = min(ans,a[xyc[i][0]-1]+b[xyc[i][1]-1]-xyc[i][2])
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(a[x]+b[y]-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 i in range(m)]
ans = min(a) + min(b)
for x,y,c in xyc:
  x-=1
  y-=1
  tmp = a[x] + b[y] - c
  ans = min(tmp,ans)
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):
    d,f,off=map(int,input().split())
    ans=min(ans,al[d-1]+bl[f-1]-off)
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 _ in range(m)]
ans=min(al)+min(bl)
for x,y,c in xyc:
    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()))
coupone = [list(map(int, input().split())) for _ in range(m)]

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

Solution (Python):
import sys

A, B, M = map(int, sys.stdin.readline().split())
*a, = map(int, sys.stdin.readline().split())
*b, = map(int, sys.stdin.readline().split())
xyc = zip(*[map(int, sys.stdin.read().split())] * 3)

def main():
    res = min(a) + min(b)

    for x, y, c in xyc:
        res = min(res, a[x-1] + b[y-1] - c)
    return res
    
if __name__ == '__main__':
    ans = main()
    print(ans)

Solution (Python):
A, B , M = 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_ans = a[x - 1] + b[y - 1] - c
    if tmp_ans < ans:
        ans = tmp_ans
print(ans)

Solution (Python):
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement, groupby
from math import sqrt, factorial, log
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heappushpop
import sys
stdin = sys.stdin
mod = 10**9 + 7

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

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

Solution (Python):
from sys import stdin
A,B,M = [int(x) for x in stdin.readline().rstrip().split()]
a = [int(x) for x in stdin.readline().rstrip().split()]
b = [int(x) for x in stdin.readline().rstrip().split()]
ans = min(a)+min(b)

for i in range(M):
    x,y,c = [int(x) for x in stdin.readline().rstrip().split()]
    if ans >= a[x-1] + b[y-1] - c:
        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()))

norm=min(a)+min(b)

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

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=[]
ans=10**7
for _ in range(M):
    i,j,k=map(int,input().split())
    
    ans = min(ans,a[i-1]+b[j-1]-k)
a.sort()
b.sort()
min_=a[0]+b[0]
print(min(ans,min_))