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 = list(map(int, input().split()))
B_list = list(map(int, input().split()))

ans = min(A_list) + min(B_list)
M_list = []
for m in range(M):
  M_list = list(map(int, input().split()))
  _ = A_list[M_list[0]-1] + B_list[M_list[1]-1] - M_list[2]
  ans = min(_,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()))

minc=min(a)+min(b)

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

  if cash<minc:
    minc=cash

print(minc)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def main():
    A, B, M = map(int, input().split())
    al = list(map(int, input().split()))
    bl = list(map(int, input().split()))
    disc = []
    for i in range(M):
        x, y, c = map(int, input().split())
        disc.append({"x": x, "y": y, "c": c})

    # 割引券なしの最小値
    a_min = min(al)
    b_min = min(bl)
    ans = a_min + b_min

    # 割引券をつかう場合
    for d in disc:
        c = al[d["x"] - 1] + bl[d["y"] - 1] - d["c"]
        ans = min(ans, c)

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

Submission status: Accepted

Solution code:
def resolve():
    a, b, m = map(int,input().split())
    R = list(map(int, input().split()))
    M = list(map(int, input().split()))
    X = [list(map(int, input().split())) for i in range(m)]

    ans = min(R) + min(M)
    for i in range(m):
        ans = min(ans, R[X[i][0]-1]+M[X[i][1]-1]-X[i][2])
    print(ans)

if __name__ == '__main__':
    resolve()

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())
price_A=list(map(int,input().split()))
price_B=list(map(int,input().split()))
coupon=[]
for _ in range(m):
  coupon.append(list(map(int,input().split())))
ans=min(price_A)+min(price_B)
for i in range(m):
  deprice=price_A[coupon[i][0]-1]+price_B[coupon[i][1]-1]-coupon[i][2]
  if deprice < ans:
    ans = deprice
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()))
C = [list(map(int,input().split())) for _ in range(M)]
mina = min(a)
minb = min(b)
ans = mina+minb
for i in range(M):
    if ans > a[C[i][0]-1] + b[C[i][1]-1] - C[i][2]:
        ans = a[C[i][0]-1] + b[C[i][1]-1] - C[i][2]
print(ans)

Submission status: Accepted

Solution code:
A, B, M = [int(x) for x in input().split(" ")]
As = list([int(x) for x in input().split(" ")])
Bs = list([int(x) for x in input().split(" ")])


minimumValue = 999999999
for i in range(M):
    x, y, c = [int(x) for x in input().split(" ")]
    x -= 1
    y -= 1
    minimumValue = min(minimumValue, As[x] + Bs[y] - c)

As.sort()
Bs.sort()

minimumValue = min(minimumValue, As[0] + Bs[0])
print(minimumValue)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def inp():
    return input()
def iinp():
    return int(input())
def inps():
    return input().split()
def miinps():
    return map(int,input().split())
def linps():
    return list(input().split())
def lmiinps():
    return list(map(int,input().split()))
def lmiinpsf(n):
    return [list(map(int,input().split()))for _ in range(n)]

A,B,M = miinps()
a = lmiinps()
b = lmiinps()
x = lmiinpsf(M)

mi = 10 ** 10

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

mi = min(mi,min(a)+min(b))

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()))
xyc = [list(map(int, input().split())) for i in range(M)]

ans = min(A)+min(B)

for i in range(M):
    if A[xyc[i][0]-1]+B[xyc[i][1]-1]-xyc[i][2] < ans:
        ans = A[xyc[i][0]-1]+B[xyc[i][1]-1]-xyc[i][2]

print(ans)

Submission status: Accepted

Solution code:
def main():

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

    a_list = list(map(int, input().split()))

    b_list = list(map(int, input().split()))

    min_pair = a_list[a_list.index(min(a_list))] + b_list[b_list.index(min(b_list))]

    m_list = []
    for i in range(m):
        x,y,c = map(int, input().split())
        if a_list[x-1]+b_list[y-1]-c <= min_pair:
            min_pair = a_list[x-1]+b_list[y-1]-c

    print(min_pair)


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

Submission status: Accepted

Solution code:
#gcdは3.4.3だとfractionsにある
from fractions import gcd
import math

from math import factorial as f

from math import ceil,floor,sqrt


import bisect
import re
import heapq


from copy import deepcopy
import itertools

from sys import exit

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

yes = "Yes"
no = "No"

def main():
    a,b,m = mi()
    alist = li()
    blist = li()
    ans = min(alist)+min(blist)
    for i in range(m):
        x,y,c = mi()
        ans = min(ans,alist[x-1]+blist[y-1]-c)
    print(ans)




main()

Submission status: Accepted

Solution code:
a, b, m = map(int, input().split())
aa = list(map(int, input().split()))
bb = list(map(int, input().split()))
xyc = [map(int, input().split()) for _ in range(m)]

discount = min(aa[x-1] + bb[y-1] - c for x, y, c in xyc)
cheap = min(aa) + min(bb)

print(min(discount, cheap))

Submission status: Accepted

Solution code:
a, b, m = map(int, input().split())
A_lst = list(map(int, input().split()))
B_lst = list(map(int, input().split()))
dis_lst = [[0]*3 for _ in range(m)]
for i in range(m):
    x, y, c = map(int, input().split())
    dis_lst[i][0] = x - 1
    dis_lst[i][1] = y - 1
    dis_lst[i][2] = c

min_num = min(A_lst) + min(B_lst)
for dis in dis_lst:
    sum_num = A_lst[dis[0]] + B_lst[dis[1]] - dis[2]
    if sum_num < min_num:
        min_num = sum_num

print(min_num)

Submission status: Accepted

Solution code:
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

A,B,M = LI()
a = LI()
b = LI()
x,y,c = LIR(M,3)

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a,b,m = map(int,input().split())
lia = list(map(int,input().split()))
lib = list(map(int,input().split()))
xyc = [list(map(int,input().split())) for _ in range(m)]

ans = min(lia) + min(lib)

for x,y,c in xyc:
    ans = min(ans, lia[x-1] + lib[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 _ 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 = [int(i) for i in input().split()]

a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]

min_p = min(a) + min(b)

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

Submission status: Accepted

Solution code:
A, B, M = [int(x) for x in input().split()]
A_price_list = [int(x) for x in input().split()]
B_price_list = [int(x) for x in input().split()]

discount_list = []

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


amount = min(A_price_list) + min(B_price_list)

for x, y, c in discount_list:
    tmp_price = A_price_list[x] + B_price_list[y] - c
    amount = min(tmp_price, amount)

print(amount)

Submission status: Accepted

Solution code:
A,B,M = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
K = min(a)+min(b)
X = 10**9
for i in range(M):
    x,y,c = map(int,input().split())
    S = a[x-1]+b[y-1]-c
    if S<X:
        X = S
if X<K:
    print(X)
else:
    print(K)

Submission status: Accepted

Solution code:
A,B,M=map(int,input().split())
L_A=list(map(int,input().split()))
L_B=list(map(int,input().split()))
ans=min(L_A)+min(L_B)
for i in range(M):
	X,Y,Z=map(int,input().split())
	ans=min(ans,(L_A[X-1]+L_B[Y-1]-Z))
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()]
X = [[int(x) for x in stdin.readline().rstrip().split()] for _ in range(M)]

L = []
L.append(min(a) + min(b))

for x in X:
    L.append(a[x[0]-1] + b[x[1]-1] - x[2])
    
    
print(min(L))

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 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 list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    aa,bb,m = LI()
    a = LI()
    b = LI()
    xyc = [LI() for _ in range(m)]
    r = min(a) + min(b)
    for x,y,c in xyc:
        t = a[x-1] + b[y-1] - c
        if r > t:
            r = t

    return r


print(main())

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

s = min(a)+min(b)

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

print(min(s,t))

Submission status: Accepted

Solution code:
lis = [int(x) for x in input().split()]
a = lis[0]
b = lis[1]
m = lis[2]
lis2 = []
A=[int(x) for x in input().split()]
B=[int(x) for x in input().split()]


for i in range(m):
    lis2.append([int(x) for x in input().split()])

min1 = min(A)+min(B)
cost = [A[lis2[x][0]-1] + B[lis2[x][1]-1] - lis2[x][2] for x in range(m)]
min2 = min(cost)

print(min([min1 , min2]))

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

Submission status: Accepted

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

wk = -1
for i in range(m):
    x, y, c = map(int, input().split())
    if wk == -1:
        wk = li_a[x - 1] + li_b[y - 1] - c
    else:
        wk = min(wk,li_a[x - 1] + li_b[y - 1] - c)
answer = min(wk,min(li_a) + min(li_b))
print(answer)

Submission status: Accepted

Solution code:
numA, numB, numCoupon = map(int, input().split(' '))
priceA = list(map(int, input().split(' ')))
priceB = list(map(int, input().split(' ')))

# initial best price
bestPrice = min(priceA) + min(priceB)

for n in range(numCoupon):
  # get coupon details
  typeA, typeB, discount = map(int, input().split(' '))
  # calculate price when this coupon is used
  currentPrice = priceA[typeA-1] + priceB[typeB-1] - discount
  # update best price
  if currentPrice < bestPrice:
    bestPrice = currentPrice

print(bestPrice)

Submission status: Accepted

Solution code:
p,q,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
z = [100000, 100000 ,200000]
for i in range(p):
    if(z[0] > A[i]):
        z[0] = A[i]
for i in range(q):
    if(z[1] > B[i]):
        z[1] = B[i]
for i in range(m):
    x[i],y[i],c[i] = map(int, input().split())
    if(A[x[i]-1] + B[y[i]-1] - c[i] < z[2]):
        z[2] = A[x[i]-1] + B[y[i]-1] - c[i]
print(min(z[0]+z[1], z[2]))

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 = 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 = list(map(int, input().split()))
b = list(map(int, input().split()))
l = [input().split() for i in range(m)]
ans = min(a) + min(b)

for i in range(m):
    ai = a[int(l[i][0]) - 1]
    bi = b[int(l[i][1]) - 1]
    ci = int(l[i][2])
    nc = ai + bi - ci
    ans = min(ans, nc)
print(ans)

Submission status: Accepted

Solution code:
def solve(A, B, M, a, b, x, y, c):
    best = min(a) + min(b)
    for i in range(M):
        best = min(best, a[x[i]-1] + b[y[i]-1] - c[i])
    return best

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())
print(solve(A, B, M, a, b, x, y, c))

Submission status: Accepted

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

ans1=min(ap)+min(bp)
ans=[ans1]
for i in range(m):
    ai,bj,d=map(int,input().split())
    ans2=ap[ai-1]+bp[bj-1]-d
    ans.append(ans2)
    
print(min(ans))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a,b,m = list(map(int, input().split()))
a1 = list(map(int, input().split()))
b1 = list(map(int, input().split()))
xyc = [ list(map(int, input().split())) for _ in range(m)]

ans = []
for x,y,c in xyc:
    ans.append(a1[x-1] + b1[y-1] - c)
ans.append(min(a1) + min(b1))
print(min(ans))

Submission status: Accepted

Solution code:
S = input().split()

#冷蔵庫
A = int(S[0])
#電子レンジ
B = int(S[1])
#割引券
M = int(S[2])



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


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

    if total_mini > amount:
        total_mini = amount


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

print(ans)

Submission status: Accepted

Solution code:
listA=[]

while True:
    try:
        listA.append(list(map(int,input().split())))

    except:
        break;
        

money = min(listA[1]) + min(listA[2]) 
wari = 100000000

for k in range(listA[0][2]):
    a = listA[k+3][0]
    b = listA[k+3][1]
    if wari > listA[1][a-1] + listA[2][b-1] - listA[k+3][2]:
        wari = listA[1][a-1] + listA[2][b-1] - listA[k+3][2]

if money <= wari:
    print(money)
        
else:
    print(wari)

Submission status: Accepted

Solution code:
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
nedan = set()
nedan.add(min(a) + min(b))
for i in range(M):
    j, k, l = map(int, input().split())
    nedan.add(a[j - 1] + b[k - 1] - l)
print(min(nedan))

Submission status: Accepted

Solution code:
a,b,m=map(int, input().split(" "))
alist=list(map(int, input().split(" ")))
blist=list(map(int, input().split(" ")))

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

ans = min(alist) + min(blist)

for q in qlist:
  ans = min([alist[q[0]-1] + blist[q[1]-1] - q[2],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())
  val = a[x-1] + b[y-1] - c
  ans = min(ans, val)
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())
    if a[x-1] + b[y-1] - c < ans:
        ans = a[x-1] + b[y-1] - c

print(ans)

Submission status: Accepted

Solution code:
a,b,m=map(int,input().split())
arr1=list(map(int,input().split()))
arr2=list(map(int,input().split()))
ans=min(arr1)+min(arr2)
for _ in range(m):
  x,y,c=map(int,input().split())
  tmp=arr1[x-1]+arr2[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()))
c = [list(map(int, input().split())) for i in range(m)]
ans = min(A) + min(B)
for i in range(m):
    t = A[c[i][0]-1] + B[c[i][1]-1] - c[i][2]
    ans = min(ans, t)

print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
input = sys.stdin.readline

_, _, m = map(int, input().split())
a = [int(item) for item in input().split()]
b = [int(item) for item in input().split()]
ans = min(a) + min(b)
for _ in range(m):
    x, y, c = map(int, input().split())
    x -= 1; y -= 1
    val = a[x] + b[y] - c
    if val < ans:
        ans = val

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()]
data = [list(map(int, input().split())) for _ in range(M)]

aMIN = min(a)
bMIN = min(b)

MIN = aMIN + bMIN

for k in data:
    MIN = min(MIN, a[k[0]-1]+b[k[1]-1]-k[2])


print(MIN)

Submission status: Accepted

Solution code:
num = [int(n) for n in input().split(" ")]
A, B, M = num[0], num[1], num[2]

a = [int(n) for n in input().split(" ")]
b = [int(n) for n in input().split(" ")]

data = []
for i in range(M):
    data.append([int(n) for n in input().split(" ")])


temp_min = min(a) + min(b)

for d in data:
    total = a[d[0]-1] + b[d[1]-1] - d[2]
    if temp_min > total:
        temp_min = total

print(temp_min)

Submission status: Accepted

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

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 = []
for i in range(M):
  ans.append(a[xyc[i][0]-1]+b[xyc[i][1]-1]-xyc[i][2])
mi=min(a)+min(b)
print(min(min(ans),mi))

Submission status: Accepted

Solution code:
a, b, m = map(int, input().split())
A = [int(n) for n in input().split()]
B = [int(n) for n in input().split()]
# 割引券を使った場合の最少額を求める
min_m = float('inf')
for ai, bi, c in [map(int, input().split()) for _ in range(m)]:
	if min_m > A[ai-1] + B[bi-1] - c:
		min_m = A[ai-1] + B[bi-1] - c
print(min(min(A)+min(B),min_m))

Submission status: Accepted

Solution code:
lines = []
line = input()
s = line.split(' ')
entries = int(s[2]) + 2
for i in range(entries+1):
    lines.append(line.split(' '))
    if i < entries:
        line = input()

discounts = []
for idx, line in enumerate(lines):
    if idx == 0:
        A = line[0]
        B = line[1]
        M = line[2]
    elif idx == 1:
        refrigerators = line
    elif idx == 2:
        microwaves = line
    else:
        discounts.append(line)

ref_reg = int(10 ** 5)
for r in refrigerators:
    reg = int(r)
    if ref_reg > reg:
        ref_reg = reg

ref_mic = int(10 ** 5)
for m in microwaves:
    mic = int(m)
    if ref_mic > mic:
        ref_mic = mic

ref_min = ref_reg + ref_mic
for discount in discounts:
     d = int(refrigerators[int(discount[0])-1]) + int(microwaves[int(discount[1])-1]) - int(discount[2])
     if d < ref_min:
         ref_min = d       
         
print(ref_min)

Submission status: Accepted

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

# 割引券を使った場合の最少額を求める
min_m = float('inf')
for ai, bi, c in [map(int, input().split()) for _ in range(m)]:
	if min_m > A[ai-1] + B[bi-1] - c:
		min_m = A[ai-1] + B[bi-1] - c

print(min(min(A)+min(B),min_m))

Submission status: Accepted

Solution code:
#定義
costA = []
costB = []

# ロジック
A,B,M = map(int,input().split()) # A(冷蔵庫)の種類、B(電子レンジ)の種類、M(割引券)の数
x = [[] for i in range(M)]
y = [[] for i in range(M)]
c = [[] for i in range(M)]
costA = input().split()
costB = input().split()
for i in range(M):
  x[i],y[i],c[i] = map(int,input().split()) # x[i]=割引できるA(冷蔵庫)の種類、
                                            # y[i]=割引できるB(電子レンジ)の種類、
                                            # c[i]=割引額
mincostA = int(costA[0])
for j in range(A):
  if int(costA[j]) < mincostA:
    mincostA = int(costA[j])

mincostB = int(costB[0])
for k in range(B):
  if int(costB[k]) < mincostB:
    mincostB = int(costB[k])

teika = mincostA + mincostB

for l in range(M):
  ind1 = x[l] - 1
  out1 = int(costA[ind1]) 
  ind2 = y[l] - 1
  out2 = int(costB[ind2])
  if (out1 + out2 - int(c[l])) < teika:
    teika = (out1 + out2 - int(c[l]))

print(teika)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
A, B, M = [int(_) for _ in input().split()]

La = [int(_) for _  in input().split()]
Lb = [int(_) for _ in input().split()]
Lm = [[int(_) for _ in input().split()] for _ in range(M)]

ans = min(La) + min(Lb)
for x, y, c in Lm:
    ans = min(ans, La[x-1] + Lb[y-1] - c)
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()]
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())
non_coupon_val = min(a) + min(b)
coupon_val_arr = [0 for i in range(M)]
for i in range(M):
  coupon_val_arr[i] = a[x[i]-1] + b[y[i]-1] - c[i]
coupon_val = min(coupon_val_arr)
print(min([non_coupon_val, coupon_val]))

Submission status: Accepted

Solution code:
a,b,m=map(int,input().split())
alist=tuple(map(int,input().split()))
blist=tuple(map(int,input().split()))

mlist=[]
for i in range(m):
    mlist.append(tuple(map(int,input().split())))

minimum=min(alist)+min(blist)

for i in range(m):
    tempx,tempy,tempc=mlist[i]
    discountsum=alist[tempx-1]+blist[tempy-1]-tempc
    if  discountsum < minimum:
        minimum=discountsum

print(minimum)

Submission status: Accepted

Solution code:
# coding: utf-8

A, B, m = map(int, input().split())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]

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

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

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

cost=min(alist)+min(blist)

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

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())
price_A = list(map(int, input().split()))
price_B = list(map(int, input().split()))
discounts = [list(map(int, input().split())) for i in range(M)]
ans_candidate = min(price_A) + min(price_B)

for discount in discounts:
    tmp_ans = price_A[discount[0]-1] + price_B[discount[1]-1] - discount[2]
    if tmp_ans <= ans_candidate:
        ans_candidate = tmp_ans

print(ans_candidate)

Submission status: Accepted

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
import pprint
sys.setrecursionlimit(10 ** 9)


INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


a, b, m = LI()
A = LI()
B = LI()
ret = min(A) + min(B)
for i in range(m):
    x, y, c = LI()
    ret = min(A[x -1]+B[y-1]-c, ret)


print(ret)

Submission status: Accepted

Solution code:
_, _, M = map(int, input().split(" "))
a = list(map(int, input().split(" ")))
b = list(map(int, input().split(" ")))
min = min(a) + min(b)
for i in range(M):
  x, y, c = map(int, input().split(" "))
  s = a[x-1] + b[y-1] - c
  if min > s:
    min = s
print(min)

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(ans, a[x] + b[y] - c)
print(ans)

Submission status: Accepted

Solution code:
abm = [int(i) for i in input().split(" ")]
a = [int(i) for i in input().split(" ")]
b = [int(i) for i in input().split(" ")]

xyc = []
for i in range(abm[2]):
  xyc.append([int(i) for i in input().split(" ")])

minDiscount = float("inf")
for i in xyc:
  minDiscount = min(a[i[0]-1] + b[i[1]-1] - i[2], minDiscount)

minNotDiscount = min(a) + min(b)

print(min(minDiscount, minNotDiscount))

Submission status: Accepted

Solution code:
def o():return list(map(int,input().split()))
n=o();a=o();b=o()
c=min(a)+min(b)
for i in range(n[2]):
  x=o()
  c=min(c,a[x[0]-1]+b[x[1]-1]-x[2])
print(c)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
A, B, M = map(int, input().split())
*a, = map(int, input().split())
*b, = map(int, input().split())
a_s = sorted(a)
b_s = sorted(b)
min_v = a_s[0] + b_s[0]
for _ in range(M):
    x, y, c = map(int, input().split())
    min_v = min(min_v, a[x-1] + b[y-1] - c, )
print(min_v)