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.



Sample input:
2 3 1
3 3
3 3 3
1 2 1


Sample output:
5

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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()

Submission status: Accepted

Solution code:
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

# If you use recursive call, uncomment this code
#sys.setrecursionlimit(10**6)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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()

Submission status: Accepted

Solution code:
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])

Submission status: Accepted

Solution code:
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

# main()
print(main())

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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)
# else:
#     sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(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()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
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)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def solve():
    # N = int(input())
    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()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
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))  # type: int
    B = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(A)]  # type: "List[int]"
    b = [int(next(tokens)) for _ in range(B)]  # type: "List[int]"
    x = [int()] * (M)  # type: "List[int]"
    y = [int()] * (M)  # type: "List[int]"
    c = [int()] * (M)  # type: "List[int]"
    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()

Submission status: Accepted

Solution code:
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()

Submission status: Accepted

Solution code:
[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)))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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())
    #print(a[i-1]+b[j-1]-k)
    ans = min(ans,a[i-1]+b[j-1]-k)
a.sort()
b.sort()
min_=a[0]+b[0]
print(min(ans,min_))

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    a,b,m=MI()
    aa=LI()
    bb=LI()
    ans=min(aa)+min(bb)
    for _ in range(m):
        x,y,c=MI()
        x,y=x-1,y-1
        ans=min(ans,aa[x]+bb[y]-c)
    print(ans)

main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
A,B,M=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
xyc=[]
for _ in range(M):
    x,y,c=map(int,input().split())
    xyc.append([x,y,c])
mi=min(a)+min(b)
for i in range(M):
    e=xyc[i][0]-1
    f=xyc[i][1]-1
    g=xyc[i][2]
    h=a[e]+b[f]-g
    mi =min(mi,h)
print(mi)

Submission status: Accepted

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

Submission status: Accepted

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

t = []
for i in range(m):
    x, y, c = map(int, input().split())
    t.append(al[x-1]+bl[y-1]-c)
a_min = min(al)
b_min = min(bl)
t.append(a_min+b_min)

print(min(t))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
A,B,M = map(int,input().split())
*a, = map(int,input().split())
*b, = map(int,input().split())
XYC = [list(map(int,input().split())) for _ in [0]*M]

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

Submission status: Accepted

Solution code:
_, _, 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):
  xi, yi, ci = map(int, input().split())
  px = a[xi-1] + b[yi-1] - ci
  if px < ans:
    ans = px

print(ans)

Submission status: Accepted

Solution code:
def solve():
    A, B, M = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    x, y, c = [0] * M, [0] * M, [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)


if __name__ == '__main__':
    solve()

Submission status: Accepted

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

Submission status: Accepted

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

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a,b,m=map(int, input().split())  
A=list(map(int, input().split()))
B=list(map(int, input().split()))
ans=min(A)+min(B)
xyc=[]
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)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

a,b,m = LI()
A = LI()
B = LI()
xyc = [LI() 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)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
A,B,m=map(int,input().split())
a=[int(j) for j in input().split()]
b=[int(j) for j in input().split()]

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

print(ans)