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())
ta = input().split()
tb = input().split()
a = [int(s) for s in ta]
b = [int(s) for s in tb]
mp = min(a) + min(b)
for i in range(M):
    x, y, c = map(int, input().split())
    w = a[x-1] + b[y-1] - c
    if mp > w:
        mp = w
print(mp)

Submission status: Accepted

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

ans = min(ai)+min(bi)
for k in range(m):
    ak, bk, mk = map(int,input().split())
    ansk = ai[ak-1]+bi[bk-1]-mk
    if ansk<ans:
        ans = ansk
print(ans)

Submission status: Accepted

Solution code:
a, b, m = map(int,str(input()).split())
a_cost_map = map(int,str(input()).split())
a_cost = list(a_cost_map)
b_cost_map = map(int,str(input()).split())
b_cost = list(b_cost_map)

coupons_map = [str(input()).split() for i in range(m)]
coupons_map_all =  [[int(coupons_map[i][t]) for t in range(len(coupons_map[i]))] for i in range(len(coupons_map))]

minimum = min(a_cost) + min(b_cost)
for coupon in coupons_map_all:
    coupon_use = (a_cost[coupon[0]-1] +  b_cost[coupon[1]-1] - coupon[2]) 
    if minimum > coupon_use:
        minimum = coupon_use
print(minimum)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

def hitachi2020b(a, b, discount):
    min_a = a[0]
    for i in range(len(a)):
        if a[i] < min_a:
            min_a = a[i]
    min_b = b[0]
    for i in range(len(b)):
        if b[i] < min_b:
            min_b = b[i]
    min_val = min_a + min_b

    for k in range(len(discount)):
        disc = discount[k]
        cand_a = disc[0] - 1
        cand_b = disc[1] - 1
        cand_val = a[cand_a] + b[cand_b] - disc[2]
        if cand_val < min_val:
            min_val = cand_val

    return min_val

###
# main
if(__name__ == '__main__'):
    # input
    num_a, num_b, m = map(int, input().split(" "))
    val_a = list(map(int, input().split(" ")))
    val_b = list(map(int, input().split(" ")))

    discount = []
    for k in range(m):
        discount.append(list(map(int, input().split(" "))))
    
    accomplishment = hitachi2020b(val_a, val_b, discount)
    
    # output
    print(accomplishment)
# else:
    # do nothing

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(min(a)+min(b),ans)
print(ans)

Submission status: Accepted

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

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

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

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 = []
 
while M>0:
    ticket.append(tuple(map(int, input().split())))
    M -= 1
 
lowest = min(a)+min(b)
 
for ele in ticket:
    t = a[ele[0]-1] + b[ele[1]-1] - ele[2]
    if t < lowest:
        lowest = t
print(lowest)

Submission status: Accepted

Solution code:
A, B, M = input().split()
A=int(A)
B=int(B)
M=int(M)
a = list(map(int, input().split()))
b = list(map(int, input().split()))
x = [list(map(int, input().split())) for i in range(M)]
 
dis = []
for i in range(M):
    m = x[i][0]-1
    n = x[i][1]-1
    dis.append(a[m] + b[n] - x[i][2])
    
a.sort()
b.sort()
 
dis.append(a[0]+b[0])
 
print(min(dis))

Submission status: Accepted

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

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

    # without discount
    total = min(a) + min(b)

    # with discount
    for i in range(M):
        t = a[x[i] - 1] + b[y[i] - 1] - c[i]
        if t < total:
            total = t

    print(total)

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 = []
waribiki = []

for _ in range(M):
    x,y,c = map(int,input().split())
    waribiki.append(a[x-1]+b[y-1]-c)
a_min=min(a)
b_min=min(b)
ab_min = a_min+b_min
waribiki_min = min(waribiki)
print(min(waribiki_min,ab_min))

Submission status: Accepted

Solution code:
a, b, m = map(int, input().split())
ai = list(map(int,input().split()))
bi = list(map(int,input().split()))
xi = [list(map(int, input().split())) for i in range(m)]
ans = []
ans.append(min(ai)+ min(bi))
for i in range(0,m):
    ans.append(ai[xi[i][0]-1] + bi[xi[i][1]-1] - xi[i][2])

print(min(ans))

Submission status: Accepted

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

#2次元配列
grid = []
for i in range(M):
    array = list(map(int, input().strip().split()))
    grid.append(array)
    
sum_fee = []
a_min = min(a)
b_min = min(b)
sum_fee.append(a_min+b_min)

for l, m, n in grid:
    sum_fee.append(a[l-1] + b[m-1] - n)
    

print(min(sum_fee))

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

ans = []

ans.append(min(list_a)+min(list_b))

for i in range(m):
    k = list_m[i]
    ans.append(list_a[k[0]-1] + list_b[k[1]-1] - k[2])

print(min(ans))

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()))
w_list = []
for i in range(M):
    a, b, c = map(int, input().split())
    w_list.append(a_list[a - 1] + b_list[b - 1] - c)

print(min(min(w_list), min(a_list) + min(b_list)))

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()))
list_1=[list(map(int,input().split())) for i in range(M)]
L=min(list_A)+min(list_B)
list_2=[]
for k in range(M):
  cost=list_A[list_1[k][0]-1]+list_B[list_1[k][1]-1]-list_1[k][2]
  list_2.append(cost)
if L>=min(list_2):
  print(min(list_2))
else:
  print(L)

Submission status: Accepted

Solution code:
a,b,m = map(int,input().split())
alist = list(int(x) for x in input().split())
blist = list(int(x) for x in input().split())
x = []
y = []
c = []
for i in range(m):
  inp1,inp2,inp3 = map(int,input().split())
  x.append(inp1)
  y.append(inp2)
  c.append(inp3)
mini = min(alist) ++ min(blist)
for i in range(m):
  if alist[x[i]-1] + blist[y[i]-1] - c[i] < mini:
    mini = alist[x[i]-1] + blist[y[i]-1] - c[i]
print(mini)

Submission status: Accepted

Solution code:
A, B, M = map(int, input().split())
x, y, c = [0] * M, [0] * M, [0] * M
a = list(map(int, input().split()))
b = list(map(int, input().split()))
for i in range(M):
    x[i], y[i], c[i] = map(int, input().split())
ans, sav = float("inf"), 0
for j in range(M):
    sav = a[x[j] - 1] + b[y[j] - 1] - c[j]
    if ans > sav:
        ans = sav

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()))
x = []
y = []
c = []
for i in range(M):
    X, Y, C= map(int, input().split())
    x.append(X-1)
    y.append(Y-1)
    c.append(C)

value = []
for i in range(M):
    v = a[x[i]] + b[y[i]] - c[i]
    value.append(v)

mindefalt = min(a) + min(b)
minvalue = min(value)

if mindefalt > minvalue:
    print(minvalue)
else:
    print(mindefalt)

Submission status: Accepted

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

ans = min(a) + min(b)
for i in range(M):
    if a[matrix[i][0]-1] + b[matrix[i][1]-1] - matrix[i][2] < ans:
        ans = a[matrix[i][0]-1] + b[matrix[i][1]-1] - matrix[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()))
min_price=min(a)+min(b)
for i in range(M):
    tmp_price=10000
    m=list(map(int,input().split()))
    tmp_price=a[m[0]-1]+b[m[1]-1]-m[2]
    if min_price>tmp_price:
        min_price=tmp_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()))
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:
numberOfDiscountTickets=input().split()[2]
refrigirators=input().split()
microwaves=input().split()
discounts=[]
for i in range(int(numberOfDiscountTickets)):
 discounts.append(input().split())
temp1=sorted(refrigirators)
temp2=sorted(microwaves)
minimumPrice=int(temp1[0])+int(temp2[0])
checkMin=0
for discount in discounts:
 checkMin=int(refrigirators[int(discount[0])-1])+int(microwaves[int(discount[1])-1])-int(discount[2])
 if checkMin<minimumPrice:
  minimumPrice=checkMin
print(minimumPrice)

Submission status: Accepted

Solution code:
a, b ,c = map(int,input().split(" "))
ap =[]
ap = list(map(int,input().split(" ")))
bp =[]
bp = list(map(int,input().split(" ")))
lowest = 10000000
ma = min(ap)
mb = min(bp)
lowest = ma +mb
for _ in range(c):
    x, y ,z = map(int,input().split(" "))
    dis = ap[x-1] + bp[y-1] - z
    lowest = min(lowest,dis)
print(lowest)

Submission status: Accepted

Solution code:
i=list(map(int, input().split()))
a=list(map(int, input().split()))
b=list(map(int, input().split()))
A=i[0]
B=i[1]
M=i[2]
x = []
y = []
c = []
for j in range(M):
    x1,y1,c1=[int(j) for j in input().split()]
    x.append(x1)
    y.append(y1)
    c.append(c1)
d=200001
e=100001
f=100001
for k in range (A):
    if a[k]<e:
        e=a[k]

for l in range (B):
    if b[l]<f:
        f=b[l]
d=e+f

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

print(d)

Submission status: Accepted

Solution code:
R = lambda: tuple(map(int, input().split()))
A, B, M = R()
a, b = R(), R()
d = (R() for _ in range(M))
print(min(min(a) + min(b), *(a[x - 1] + b[y - 1] - c for x, y, c in d)))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import numpy as np

A, B, M = input().split(" ")
a = np.array(input().split(" "), dtype=np.int64)
b = np.array(input().split(" "), dtype=np.int64)

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

x_np = np.array(x_list, dtype=np.int64)

# 候補1はa,bの最小値同士で足したもの
a_min = a.min()
b_min = b.min()
a_min_idx = np.argmin(a)
b_min_idx = np.argmin(b)

cand = x_np[(x_np[:,0]==a_min_idx)&(x_np[:,1]==b_min_idx)]
if cand.shape[0]>0:
  tgt_idx = np.argmax(cand, axis=0)[2]
  cand_payment1 = a_min + b_min - cand[tgt_idx,2]
else:
  cand_payment1 = a_min + b_min
  
# 候補2は割引して最安
val_list = []
for x,y,c in x_np:
  val_list.append(a[x-1] + b[y-1] - c)
  
val_np = np.array(val_list)
cand_payment2 = val_np.min()


if cand_payment1<cand_payment2:
  print(cand_payment1)
else:
  print(cand_payment2)

Submission status: Accepted

Solution code:
import itertools

a,b,m = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
P = [list(map(int,input().split())) for i in range(m)]
y = []
#普通に足算する
aa = min(A)
bb = min(B)
xx =aa+bb

#割引券使う
for i in range(m):
  y.append(A[P[i][0]-1] + B[P[i][1]-1] - P[i][2])
#min出す
yy = min(y)

print(min(xx,yy))

Submission status: Accepted

Solution code:
A, B, M = map(int, input().split())
a, b = [], []
a = list(map(int, input().split()))
b = list(map(int, input().split()))
x, y, c = [], [], []
for i in range(M):
  tmp = list(map(int, input().split()))
  x.append(tmp[0])
  y.append(tmp[1])
  c.append(tmp[2])

# 割引券なし
min_a, min_b, min_total_wo = 10**5+1, 10**5+1, 0
for i in range(A):
  if min_a > a[i]:
    min_a = a[i]
for i in range(B):
  if min_b > b[i]:
    min_b = b[i]
min_total_wo = min_a + min_b
  
# 割引券あり
min_total_w = 2*10**5+1
for i in range(M):
  tmp = a[x[i]-1] + b[y[i]-1] - c[i]
  if min_total_w > tmp:
    min_total_w = tmp
if min_total_wo < min_total_w:
  print(min_total_wo)
else:
  print(min_total_w)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

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

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

i = 200000


for j in range(M):
    
    #c = 'c' + str(j)
    c =  list(map(int, input().split()))
    ma = c[0] - 1
    mb = c[1] - 1
    h = a[ma] + b[mb] - c[2]

    if i >= h:
        i = h

m = min(a) + min(b)

if i >= m:
    i = m

print(i)

Submission status: Accepted

Solution code:


N_A, N_B, N_M = map(int,input().split(" "))
A = list(map(int,input().split(" ")))
B = list(map(int,input().split(" ")))
M = [list(map(int,input().split(" "))) for i in range(N_M)]

candidates = [min(A)+min(B),]

for m in M:
    #print(A[m[0]-1] + B[m[1]-1] - m[2])
    candidates.append(A[m[0]-1] + B[m[1]-1] - m[2])

print(min(candidates))

Submission status: Accepted

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

a_l = list(map(int, input().split()))
b_l = list(map(int, input().split()))
#
m_l = []
for i in range(m):
    m_l.append(list(map(int, input().split())))
score = float('inf')
min_norm = min(a_l) + min(b_l)
sale_l = []
for m_ in m_l:
    sale_l.append(a_l[m_[0]-1]+b_l[m_[1]-1] - m_[-1])
print(min(min_norm,min(sale_l)))

Submission status: Accepted

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

X = []
Y = []
C = []
total = 2*10**5
for i in range(m):
    x,y,c = map(int,input().split())
    X.append(x)
    Y.append(y)
    C.append(c)
for i in range(m):
    result = int(A[int(X[int(i)])-1])+int(B[int(Y[int(i)])-1])-int(C[int(i)])
    if (total > result):
        total = result
#print(int(min(A))+int(min(B)))
if(int(min(A))+int(min(B))>total):
    print(total)
else:
    print(int(min(A))+int(min(B)))

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_cost = min(a_list)+min(b_list)
for _ in range(M):
    x,y,c = map(int,input().split())
    cost = a_list[x-1] + b_list[y-1] -c
    if cost<min_cost:
        min_cost = cost
print(min_cost)

Submission status: Accepted

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

a_l = list(map(int, input().split()))
b_l = list(map(int, input().split()))
m_l = []
for i in range(m):
    m_l.append(list(map(int, input().split())))
score = float('inf')
min_norm = min(a_l) + min(b_l)
sale_l = []
for m_ in m_l:
    sale_l.append(a_l[m_[0]-1]+b_l[m_[1]-1] - m_[-1])
print(min(min_norm,min(sale_l)))

Submission status: Accepted

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

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

for i in range(M):
    x_i, y_i, c_i = map(int, input().split())
    minus = a[x_i - 1] + b[y_i - 1] - c_i
    s.append(minus)

print(min(s))

Submission status: Accepted

Solution code:
R = lambda: tuple(map(int, input().split()))
A, B, M = R()
a, b = R(), R()
d = (R() for _ in range(M))
print(min([min(a) + min(b)] + [a[x - 1] + b[y - 1] - c for x, y, c in d]))

Submission status: Accepted

Solution code:
abm = [int(n) for n in input().split()]

a = abm[0]
b = abm[1]
m = abm[2]
am, bm = 1000000, 1000000
al = [int(n) for n in input().split()]
bl = [int(n) for n in input().split()]
for i in al:
    if am > i:
        am = i
for i in bl:
    if bm > i:
        bm = i
ans = am + bm

for i in range(m):
    x, y, c = map(int, input().split())
    x = x - 1
    y = y - 1
    cur = al[x] + bl[y] - c
    if cur < ans:
        ans = cur

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()))
max=min(al)+min(bl)
for i in range (m):
    cl=list(map(int,input().split()))
    if(al[cl[0]-1]+bl[cl[1]-1]-cl[2]<max):
        max=al[cl[0]-1]+bl[cl[1]-1]-cl[2]
print(max)

Submission status: Accepted

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

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

z=min(a)+min(b)
m=0
while m<M:
  s=[int(k) for k in input().split()]
  x=s[0]
  y=s[1]
  c=s[2]
  p=a[x-1]+b[y-1]-c
  if p<=z:
    z=p 
  m=m+1
print(z)

Submission status: Accepted

Solution code:
A,B,M = [int(x) for x in input().split()]
A_list = [int(x) for x in input().split()]
B_list = [int(y) for y in input().split()]
discount = []
min = 10000000
for _ in range(M):
  case = [int(x) for x in input().split()]
  discount.append(case)

min_a = sorted(A_list)[0]
min_b = sorted(B_list)[0]
 
for i in range(M):
  temp = A_list[discount[i][0]-1] + B_list[discount[i][1]-1] - discount[i][2]
  if temp < min:
    min = temp
    
if min_a + min_b > min:
  print(min)
else:
  print(min_a + min_b)

Submission status: Accepted

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

pa = [int(p) for p in input().split()]
pb = [int(p) for p in input().split()]

pc = []

for c in range(m):
  x, y, d = list(map(int, input().split()))
  pc.append(pa[x-1]+pb[y-1]-d)
  
min_c = min(pc)
if min_c<0:
  min_c=0
min_ab = min(pa)+min(pb)

if min_c < min_ab:
  print(min_c)
else:
  print(min_ab)

Submission status: Accepted

Solution code:
# input
a_n, b_n, m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
x = [input().split() for i in range(m)]

# calc
min_price = min(a) + min(b)
for p in x:
   tmp_price = int(a[int(p[0])-1]) + int(b[int(p[1])-1]) - int(p[2])
   if tmp_price < min_price:
       min_price = tmp_price
print(min_price)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

A,B,M = [int(i) for i in input().rstrip().split()]
a_list = [int(i) for i in input().rstrip().split()]
b_list = [int(i) for i in input().rstrip().split()]
xyc_list = [list(map(int, input().rstrip().split())) for i in range(M)]
#-----

min_price = min(a_list) + min(b_list)

for x,y,c in xyc_list:
    price_discount = a_list[x-1] + b_list[y-1] - c
    min_price = min( min_price, price_discount)

print(min_price)

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()]
c = {}
m = 2000000
for i in range(M):
    x, y, c2 = map(int, input().split())
    c[(x, y)] = c2
    value = a[x-1] + b[y-1] - c2
    if m > value:
        m = value

if (min(a), min(b)) in c:
    print(m)
else:
    if m > min(a) + min(b):
        print(min(a) + min(b))
    else:
        print(m)

Submission status: Accepted

Solution code:
line1 = input().split()
price_a = input().split()
price_b = input().split()
min_a = int(min(price_a))
min_b = int(min(price_b))
n = int(line1[2])
candidate = [min_a+min_b]
for i in range(n):
  discount_data = input().split()
  target_a = int(discount_data[0])
  target_b = int(discount_data[1])
  discount = int(discount_data[2])
  total = int(price_a[target_a -1]) + int(price_b[target_b -1]) -discount
  candidate.append(total)
print(min(candidate))

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):
    q = list(map(int, input().split()))
    x = a[q[0]-1] + b[q[1]-1] - q[2]
    ans.append(x)
print(min(ans))

Submission status: Accepted

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

ai = list(map(int,input().split()))
bi = list(map(int,input().split()))

min_b = min(bi)
min_a = min(ai)

price = float('inf')
for i in range(m):
  mi = list(map(int,input().split()))
  if price > ai[mi[0]-1] + bi[mi[1]-1] -mi[2]:
  	price = ai[mi[0]-1] + bi[mi[1]-1] -mi[2]

if price < min_a + min_b:
  print(price)
else:
  print(min_a + min_b)

Submission status: Accepted

Solution code:
A,B,M = (int(x) for x in input().split())
a_list = [int(x) for x in input().split()]
b_list = [int(x) for x in input().split()]
min_yen = min(a_list)+min(b_list)
m_list = []
for i in range((M)):
    m = [int(x) for x in input().split()]
    a = a_list[m[0]-1]
    b = b_list[m[1]-1]
    m = m[2]
    coupon_used = (a+b)-m
    min_yen = min(min_yen,coupon_used)    

print(min_yen)

Submission status: Accepted

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

Submission status: Accepted

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

xyc = [0]*int(abm[2])

aa = input().split()
bb = input().split()
mi = [0]*int(abm[2])

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

for i in range(0,int(abm[2])):
  x = int(xyc[i][0]) - 1
  y = int(xyc[i][1]) - 1
  c = int(xyc[i][2])
  mi[i] = int(aa[x]) + int(bb[y]) - c

ab = 0
aa =  [int(s) for s in aa]
bb =  [int(s) for s in bb]
ab = min(aa) + min(bb)
mi.append(ab)
print(min(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()))
x = []
y = []
c = []
for i in range(m):
    xi, yi, ci = map(int, input().split())
    x.append(xi)
    y.append(yi)
    c.append(ci)
ans = min(a) + min(b)
for j in range(m):
    kk = a[x[j]-1] + b[y[j]-1] - c[j]
    if ans > kk:
        ans = kk
print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a1 = sorted(a)
b1 = sorted(b)
z = [list(map(int, input().split())) for _ in range(M)]

num1 = a1[0] + b1[0]
# print("num1:", num1)
for i in range(M):
    x, y, c = z[i]
    num = a[x - 1] + b[y - 1] - c
    if num < num1:
        num1 = num
print(num1)

Submission status: Accepted

Solution code:
a, b, c = list(map(int,input().split()))
aa = list(map(int,input().split()))
bb = list(map(int,input().split()))
cc = [list(map(int,input().split())) for i in range(c)]
ans = 0

for i in range(c):
  ans1 = aa[cc[i][0] - 1] + bb[cc[i][1] - 1] - cc[i][2]
  if i == 0 :
    ans = ans1
  ans = min(ans,ans1)

aa.sort()
bb.sort()
ans2 = aa[0] + bb[0]
ans = min(ans, ans2)
  
print(ans)

Submission status: Accepted

Solution code:
A, B, M = map(int, input().split())
rfg = [int(i) for i in input().split()]
mcw = [int(i) for i in input().split()]
discount = [list(map(int, input().split())) for i in range(M)]

min_price = 10 ** 10
# 割引券を使ったときの最低価格をみる
for ticket in discount:
    tmp = rfg[ticket[0]-1] + mcw[ticket[1]-1] - ticket[2]
    if tmp < min_price:
        min_price = tmp


# 普通に買ったときの最低価格を見る
# min_priceを下回った時点でおわり
rrfg = sorted(rfg)
mmcw = sorted(mcw)

is_true = False
for i in range(A):
    for j in range(i, B):
        tmp = rrfg[i] + mmcw[j]
        if tmp >= min_price:
            break
        else:
            min_price = tmp
            is_true = True
            break

    if is_true:
        break

print(min_price)

Submission status: Accepted

Solution code:
A,B,M=map(int,input().split())
aa=list(map(int,input().split()))
bb=list(map(int,input().split()))
coupon=[list(map(int,input().split())) for i in range(M)]
mini=2*(10**5)
for j in range(M):
    p_a=coupon[j][0]
    p_b=coupon[j][1]
    p_c=coupon[j][2]
    ans=aa[p_a-1]+bb[p_b-1]-p_c
    if ans<mini:
            mini=ans
mosi=min(aa)+min(bb)
if mosi<mini:
    mini=mosi

print(mini)

Submission status: Accepted

Solution code:
s = list(map(int, input().split(" ")))

a = s[0]
b = s[1]
m = s[2]

a_l = list(map(int, input().split(" ")))
b_l = list(map(int, input().split(" ")))

ans = min(a_l) + min(b_l)

for i in range(m):
    x = list(map(int, input().split(" ")))
    if ans > (a_l[x[0] - 1] + b_l[x[1] -1] - x[2]):
        ans = a_l[x[0] -1] + b_l[x[1] -1] - x[2]


print(ans)

Submission status: Accepted

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

ref = list(map(int, input().split()))
mic = list(map(int, input().split()))

price = min(ref)+min(mic)

for i in range(M):
    arg = list(map(int, input().split()))
    val = ref[arg[0]-1]+mic[arg[1]-1]-arg[2]
    if price > val:
        price = val

print(price)

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()))
mi=min(a)+min(b)
for i in range(0,M):
  Data=list(map(int, input().split()))
  wari=a[Data[0]-1]+b[Data[1]-1]-Data[2]
  if(mi>wari):
    mi=wari
print(mi)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
A, B, M = map(int,  input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))

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

a.sort()
b.sort()

sum.append(a[0] + b [0])

sum.sort()

i=0
while sum[i] < 0:
        i+=0
print(sum[i])

Submission status: Accepted

Solution code:
a,b,m=(int(x) for x in input().split())
a_list=[int(x) for x in input().split()]
b_list=[int(x) for x in input().split()]

min_price=min(a_list)+min(b_list)

for count in range(m):
    x,y,c=(int(x) for x in input().split())
    discount_price=a_list[x-1]+b_list[y-1]-c
    if discount_price<min_price:
        min_price=discount_price
    else:
        continue
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()))

miniC = min(a) + min(b)

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

print(miniC)

Submission status: Accepted

Solution code:
a, b, m = map(int, input().split())
ref = list(map(int, input().split()))
micro = list(map(int, input().split()))
tk = [list(map(int, input().split())) for i in range(m)]

mini = min(ref) + min(micro)

amount = 10 ** 6
for i in tk:
    if ref[i[0]-1] + micro[i[1]-1] - i[2] < amount:
        amount = ref[i[0]-1] + micro[i[1]-1] - i[2]

print(min(mini, amount))

Submission status: Accepted

Solution code:
a, b, m = map(int, input().split())
a_l = list(map(int, input().split()))
b_l = list(map(int, input().split()))
x_y_c = [list(map(int, input().split())) for _ in range(m)]

a_l_s = sorted(a_l)
b_l_s = sorted(b_l)

min_price = (10 ** 5) * 3
for i in range(m):
    price = a_l[x_y_c[i][0] - 1] + b_l[x_y_c[i][1] - 1] - x_y_c[i][2]
    if price < min_price:
        min_price = price

tmp = a_l_s[0] + b_l_s[0]
if tmp < min_price:
    print(tmp)
else:
    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())) 

x = [0] * M
y = [0] * M
c = [0] * M

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

print(ans)

Submission status: Accepted

Solution code:

input_line = input()
Line = input_line.split()
Line = [int(s) for s in Line]

input_line = input()
reizou = input_line.split()
reizou = [int(s) for s in reizou]

# print(reizou)

input_line = input()
densi = input_line.split()
densi = [int(s) for s in densi]

# print(densi)

hutuu_min = min(reizou)+min(densi)
# print(hutuu_min)

for i in range(Line[2]):
    input_line = input()
    ticket = input_line.split()
    ticket = [int(s) for s in ticket]
    # print(ticket)
    ticket_min = reizou[ticket[0]-1]+densi[ticket[1]-1]-ticket[2]
    
    if ticket_min < hutuu_min:
        hutuu_min = ticket_min

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

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

r=min(a)
d=min(b)

W=[]
for i in C:
    w=a[i[0]-1]+b[i[1]-1]-i[2]
    W.append(w)

print(min(r+d,min(W)))

Submission status: Accepted

Solution code:
ABM = list(map(int, input().split()))
price_A = list(map(int, input().split()))
price_B = list(map(int, input().split()))

waribiki = []
for i in range(ABM[2]):
    waribiki.append(list(map(int, input().split())))

result = []
for i in waribiki:
    result.append(price_A[i[0] - 1] + price_B[i[1] - 1] - i[2])

result.append(min(price_A) + min(price_B))

print(min(result))

Submission status: Accepted

Solution code:
(A, B, M) = [int(k) for k in input().split(' ')]
a = [int(k) for k in input().split(' ')]
b = [int(k) for k in input().split(' ')]
coupons = []
for i in range(M):
  coupons.append([int(k) for k in input().split(' ')])

price = min(a) + min(b)
for c in coupons:
  pr = a[c[0]- 1] + b[c[1]- 1] - c[2]
  if pr < price:
    price = pr

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

Submission status: Accepted

Solution code:
a, b, m = list(map(int, input().split()))
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
sum_list = []

min_sum = min(a_list) + min(b_list)


for i in range(m):
    x, y, c = list(map(int, input().split()))
    sum = a_list[x - 1] + b_list[y - 1] - c
    sum_list.append(sum)

print(min(min(sum_list), min_sum))