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

min_num=min(a_list)+min(b_list)
for i in range(m):
  x,y,c=map(int,input().split())
  num = a_list[x-1] + b_list[y-1] -c
  min_num=min(min_num,num)
  
print(min_num)

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

minPrice = min(price_a) + min(price_b)

for i in range(m):
	x,y,c = map(int,input().split())
	price = price_a[x-1] + price_b[y-1] -c
	if price < minPrice:
		minPrice = price

print(minPrice)

Submission status: Accepted

Solution code:
import sys
import numpy as np

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

A, B, M =map(int, readline().split())
a = np.array(readline().split(), np.int64)
b = np.array(readline().split(), np.int64)

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

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

Submission status: Accepted

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

alis = list(map(int, input().split()))
blis = list(map(int, input().split()))

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

    ans = min(ans, t)

print(ans)

Submission status: Accepted

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


for n in range(M):
    m.append([int(s) for s in input().split()])

minValue = min(a) + min(b)

for i in range(M):
    discountPrice = a[m[i][0] - 1] + b[m[i][1] - 1] - m[i][2]
    if discountPrice  < minValue:
        minValue = discountPrice

print(minValue)

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 m in range(M)]
ans = min(a)+min(b)
for m in range(M):
  tmp = a[XYC[m][0]-1]+b[XYC[m][1]-1]-XYC[m][2]
  ans = min(tmp, ans)
print(ans)

Submission status: Accepted

Solution code:
'''
Created on 2020/08/20

@author: harurun
'''
def main():
  import sys
  pin=sys.stdin.readline
  
  A,B,M=map(int,pin().split())
  a=list(map(int,pin().split()))
  b=list(map(int,pin().split()))
  
  ans=min(a)+min(b)
  
  for _ in [0]*M:
    x,y,c=map(int,pin().split())
    t=a[x-1]+b[y-1]-c 
    if t<ans:
      ans=t 
  print(ans)
  return 

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

lst=[]
for i in range(m):
  x,y,z=list(map(int,input().split()))
  lst.append([x,y,z])
  
ans=min(aa)+min(bb)

for i in lst:
  ans=min(ans,aa[i[0]-1]+bb[i[1]-1]-i[2])
  
  
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()]
xyc=[[int(i)for i in input().split()]for j in range(M)]
res=min(a)+min(b)
for x,y,c in xyc:
    tmp=a[x-1]+b[y-1]-c
    res=min(res,tmp)
print(res)

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

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, N = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
l = []
l.append(min(a) + min(b))
for _ in range(N):
  aq, bq, d = map(int, input().split())
  l.append( a[aq-1] + b[bq-1] - d )
print(min(l))

Submission status: Accepted

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

A = int(lst1[0])
B = int(lst1[1])
M = int(lst1[2])

list_A = input().split()
list_B = input().split()

for i in range(A):
   list_A[i] = int(list_A[i])

for i in range(B):
   list_B[i] = int(list_B[i])

result = min(list_A) + min(list_B)

list_M = []

for i in range(M):
   lst2 = input().split()
   n = list_A[int(lst2[0]) - 1] + list_B[int(lst2[1]) - 1] - int(lst2[2])
   if n < result:
      result = n

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()))
l=[list(map(int,input().split())) for _ in range(m)]
ans=min(a)+min(b)
for x,y,c in l:
    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()))
nooff=sorted(a)[0]+sorted(b)[0]
withoff=[]
for i in range(M):
  x,y,c=map(int,input().split())
  off=a[x-1]+b[y-1]-c
  withoff.append(off)
print(min(sorted(withoff)[0],nooff))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
from collections import Counter
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())

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

ans = INF
for i in range(M):
    x, y, c = map(int, input().split())
    x -= 1
    y -= 1
    now = A[x] + B[y] - c
    ans = min(now, ans)
min_a = min(A)
min_b = min(B)
ans = min(ans, min_a + min_b)
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=[]
d=[]
for i in range(M):
    c.append(list(map(int,input().split())))
C=min(a)+min(b)
for i in range(0,M):
    d.append(a[(c[i][0]-1)]+b[(c[i][1]-1)]-c[i][2])
D=min(d)
print(min(C,D))

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)]
# print(xyc)
cost = []
cost.append(min(a) + min(b))
for x, y, c in xyc:
    tmp = a[x - 1] + b[y - 1] - c
    cost.append(tmp)
print(min(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 _ 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 _ 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:
#B - Nice Shopping 
A,B,M = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
X = []
Y = []
C = []
for i in range(M):
    x,y,c = map(int,input().split())
    X.append(x)
    Y.append(y)
    C.append(c)

#割引券を使う場合
pay_sale = [a[i-1]+b[j-1]-k for i,j,k in zip(X,Y,C)]
pay_ticket = min(pay_sale) 
#使わない場合
pay = min(a) + min(b)
print(min(pay,pay_ticket))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np

lenA, lenB, M = map(int, input().split())

A = np.array(list(map(int, input().split())))
B = np.array(list(map(int, input().split())))
X = np.zeros((M, 3), dtype=int)

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

ans = min(A) + min(B)

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

Submission status: Accepted

Solution code:
import math


def resolve():
    import sys
    input = sys.stdin.readline
    # row = [int(x) for x in input().rstrip().split(" ")]
    # n = int(input().rstrip())

    abm = [int(x) for x in input().rstrip().split(" ")]
    a_list = [int(x) for x in input().rstrip().split(" ")]
    b_list = [int(x) for x in input().rstrip().split(" ")]

    # 最小値
    ans = min(a_list) + min(b_list)

    for i in range(abm[2]):
        xyc = [int(x) for x in input().rstrip().split(" ")]
        price = a_list[xyc[0] - 1] + b_list[xyc[1] - 1] - xyc[2]
        if price < ans:
            ans = price

    print(ans)

if __name__ == "__main__":
    resolve()

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

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = min(a) + min(b)

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

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

Submission status: Accepted

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

answer=min(alist)+min(blist)
for _ in range(M):
  x,y,c=map(int,input().split())
  disc=alist[x-1]+blist[y-1]-c
  answer=min(answer,disc)
  
print(answer)

Submission status: Accepted

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

ans = min(a) + min(b)

for n in xyc:
    ans = min(ans, a[n[0]] + b[n[1]] - n[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()))

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

minmoney = min(a) + min(b)

for obj in xyc:
    summoney = a[obj[0] - 1] + b[obj[1] - 1] - obj[2]
    minmoney = min(minmoney, summoney)

print(minmoney)

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
A, B, M = [int(a) for a in input().split()]
a = [int(ai) for ai in input().split()]
b = [int(bi) for bi in input().split()]
x = []
y = []
c = []
for _ in range(M):
    xi, yi, ci = [int(xyc) for xyc in input().split()]
    x.append(xi)
    y.append(yi)
    c.append(ci)

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

print(min_price)

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())
  cost = A[x-1] + B[y-1] - c
  if cost < ans:
    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()))
D=[]
for i in range(M):
    D.append(list(map(int,input().split())))
    
S=min(a)+min(b)
P=[]
for i in range(M):
    P.append(a[D[i][0]-1]+b[D[i][1]-1]-D[i][2])
P.append(S)
print(min(P))

Submission status: Accepted

Solution code:
A, B, M = map(int, input().split())
*a, = map(int, input().split())
*b, = map(int, input().split())
ans = 10**20

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

a.sort()
b.sort()

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

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

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

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

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

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

print(minn)

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 i in range(m)]
x,y,c = [list(i) for i in zip(*l)]
p = min(a) + min(b)

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

print(p)

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

print(result)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
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:
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_kouho = [min(a)+min(b)] + [a[x-1]+b[y-1]-c for x, y, c in xyc]
print(min(ans_kouho))

Submission status: Accepted

Solution code:
# 24
A,B,M = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
Sum = float("inf")
for i in range(M):
    x,y,c = map(int,input().split())
    if a[x-1]+b[y-1]-c < Sum:
        Sum = a[x-1]+b[y-1]-c
    
a.sort()
b.sort()
if a[0]+b[0] < Sum:
    Sum = a[0]+b[0]
print(Sum)

Submission status: Accepted

Solution code:
a,b,m = map(int,input().split())
a_li = list(map(int,input().split()))
b_li = list(map(int,input().split()))
cost = min(a_li) + min(b_li)
for i in range(m):
  x,y,c = map(int,input().split())
  price = a_li[x-1] + b_li[y-1] - c
  if price < cost:
    cost = price
print(cost)

Submission status: Accepted

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

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

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

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

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

print(ans)

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

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

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline
A,B,M=list(map(int,input().split()))
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=[]
for i in range(M):
    xi,yi,ci=list(map(int,input().split()))
    c.append(a[xi-1]+b[yi-1]-ci)
a.sort()
b.sort()
c.sort()
print(min(a[0]+b[0],c[0]))

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 = input().split(' ')
A = int(A)
B = int(B)
M = int(M)
a = input().split(' ')
a = [int(a[i]) for i in range(A)]
b = input().split(' ')
b = [int(b[i]) for i in range(B)]
cost = min(a) + min(b)
for i in range(M):
  x, y, c = input().split(' ')
  x = int(x)-1
  y = int(y)-1
  c = int(c)
  if a[x] + b[y] - c < cost:
    cost = a[x] + b[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 = 0
for i in range(M):
    x, y, c = map(int, input().split())
    if i == 0:
        ans = a[x - 1] + b[y - 1] - c
        continue
    ans = min(ans, a[x - 1] + b[y - 1] - c)

a.sort()
b.sort()
ans = min(ans,a[0] + b[0])
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 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 _ in range(m):
    x, y, c = map(int, input().split())
    x -= 1
    y -= 1
    cnt = A[x] + B[y] - c
    ans = min(ans, cnt)

print(ans)

Submission status: Accepted

Solution code:
A,B,N=list(map(int,input().split()))
listA=list(map(int,input().split()))
listB=list(map(int,input().split()))
ma=sorted(listA)
mb=sorted(listB)
M=min(ma)+min(mb)
for i in range(N):
  x,y,c=list(map(int,input().split()))
  ans=listA[x-1]+listB[y-1]-c
  if ans<M:
    M=ans
print(M)

Submission status: Accepted

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

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

res = min(min(A) + min(B), res)
print(res)

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

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

Submission status: Accepted

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

vals = []
for _ in range(M):
    i, j, v = map(int, input().split())
    vals.append( a[i - 1] + b[j - 1] - v)

vals.append(min(a) + min(b))
print(min(vals))

Submission status: Accepted

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

#割引を使わなくても一番安い価格を初期値にする
total = min(a) + min(b)

for i in range(0,M,1):
    c = list(map(int,input().split()))  #割引券を入手
    kakaku = a[c[0]-1]+ b[c[1]-1] - c[2]
    if total > kakaku:
        total = kakaku

print(total)

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

Submission status: Accepted

Solution code:
import sys

A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = []
for e in sys.stdin:
  c.append(list(map(int, e.split())))

ans = min(a) + min(b)

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

print(ans)

Submission status: Accepted

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

r = tuple(map(int,input().split()))
d = tuple(map(int,input().split()))

ans = min(r)+min(d)

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

Submission status: Accepted

Solution code:
a,b,m = map(int, input().split())
aprice = list(map(int, input().split()))
bprice = list(map(int, input().split()))
c = sorted(aprice)
d = sorted(bprice)
e = c[0]+d[0]
f  =0
for i in range(m):
  x,y,k = map(int, input().split())
  f =aprice[x-1]+bprice[y-1]-k
  if(e>f):
    e = f
print(e)

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

print(min(ans))

Submission status: Accepted

Solution code:
def resolve():
    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)
    for _ in range(m):
        x, y, c = map(int, input().split())
        ans = min(ans, a_list[x-1]+b_list[y-1]-c)
    print(ans)
resolve()

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

ans = min(a)+min(b)

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

print(ans)

Submission status: Accepted

Solution code:
(A, B, M), aa, bb, *xyc = [list(map(int, s.split())) for s in open(0)]

ans = min(aa)+min(bb)

for x, y, c in xyc:
    ans = min(ans, aa[x-1]+bb[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 = map(int, input().split())
a_s = list(map(int, input().split()))
b_s = list(map(int, input().split()))
m_s =[]

for _ in range(m):
    m_s.append(list(map(int, input().split())))

mini = min(a_s) + min(b_s)

for am, bm, sale in m_s:
    mini = min(mini, a_s[am-1]+b_s[bm-1]-sale)

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 = float("inf")
for i 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())

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

ans = min(price_A)+min(price_B)

for m in range(M):
  x, y, c = map(int, input().split())
  p1 = price_A[x-1] + price_B[y-1] - c
  if p1 <= ans: ans=p1

print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

a, b, m = [int(w) for w in input().split()]
a_li = [int(w) for w in input().split()]
b_li = [int(w) for w in input().split()]

ans = min(a_li) + min(b_li)

for i in range(m):
    x, y, c = [int(w) for w in input().split()]
    t = a_li[x - 1] + b_li[y - 1] - c
    ans = min(ans, t)

print(ans)

Submission status: Accepted

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

X=[10**10]+list(map(int,input().split()))
Y=[10**10]+list(map(int,input().split()))

K=min(X)+min(Y)

for _ in range(M):
    x,y,c=map(int,input().split())
    K=min(K,X[x]+Y[y]-c)
print(K)

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

Submission status: Accepted

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

dis = []
for _ in range(M):
  dis.append(list(map(int,input().split())))

total = min(a_price)+min(b_price)

dis_total = []
for k in range(M):
  dis_total.append(a_price[dis[k][0]-1]+b_price[dis[k][1]-1]-dis[k][2])

if total <= min(dis_total):
  print(total)
else:
  print(min(dis_total))