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:
x = list(map(int,input().split(" ")))
a = x[0]
b = x[1]
m = x[2]
a_list = list(map(int,input().split(" ")))
b_list = list(map(int,input().split(" ")))
x_list =[]
money_list = []
for i in range(m):
    xi_list = []
for i in range(m):
    xi = list(map(int,input().split(" ")))
    x_list.append(xi)
    money = a_list[xi[0]-1]+b_list[xi[1]-1]-xi[2]
    money_list.append(money)
    # print(money_list)
money_list.append(min(a_list)+min(b_list))
# print(money_list)
print(min(money_list))

Submission status: Accepted

Solution code:
s = input().split(' ')
n = 0
if int(s[0]) > 0:
    n += 1
if int(s[1]) > 0:
    n += 1
if int(s[2]) > 0:
    n += int(s[2])
coupon = []
for times in range(1, n+1):
    if times == 1:
        ref = input().split(' ')
    if times == 2:
        micro = input().split(' ')
    if times > 2:
        coupon.append(input().split(' '))
price = int(ref[0]) + int(micro[0])
minPrice = price
for discount in coupon:
    price = int(ref[int(discount[0])-1]) + int(micro[int(discount[1])-1]) - int(discount[2])
    minPrice = min(minPrice, price)
ref.sort()
micro.sort()
price = int(ref[0]) + int(micro[0])
minPrice = min(minPrice, price)
print(minPrice)

Submission status: Accepted

Solution code:
x = []
y = []
z = []
x = input().split()


y = input().split() 

z = input().split() 

waribiki = []
nest = []
for i in range(int(x[2])):
    waribiki = input().split()
    nest.append(waribiki)

inu = 0
neko = 0
nedan = []
for i in range(len(nest)):
    inu = int(nest[i][0])
    neko = int(nest[i][1])
    nedan.append(int(y[inu-1])+int(z[neko-1])-int(nest[i][2]))


may = int(min(y)) + int(min(z)) 

if len(nedan) > 1:
    print(min(nedan))
elif int(may) <= min(nedan):
    print(may)
else:
    print(nedan[0])

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

ans = min(A_list) + min(B_list)
#print(ans)

for x in C_list:
    tmp = A_list[x[0]-1] + B_list[x[1]-1] - x[2]
#    print("tmp",tmp)
    if(ans > tmp):
        ans = tmp
print(ans)

Submission status: Accepted

Solution code:
A, B, M = map(int, input().split())
list_a = []
list_b = []
list_x = []
list_y = []
list_c = []
sum = []

a = input()
list_a = a.split()

b = input()
list_b = b.split()

for i in range(0, M):
    x, y, c = map(int, input().split())
    list_x.append(x)
    list_y.append(y)
    list_c.append(c)

list_d = sorted(list_a)
list_e = sorted(list_b)

sum_1 = int(list_d[0]) + int(list_e[0])
sum.append(sum_1)

for k in range(0, M):
    x_1 = int(list_x[k])
    y_1 = int(list_y[k])
    sum_2 = int(list_a[x_1-1]) + int(list_b[y_1-1]) - list_c[k]
    sum.append(sum_2)

print(min(sum))

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

#check min price
ref = min(a_price)
mi = min(b_price)
total_min = ref + mi

#check discount ticket
discount_prices_from_tickets = []
dis_price_temp = 0
for i in range(m):
  discount_prices_from_tickets.append(a_price[m_prices[i][0] - 1] + b_price[m_prices[i][1] - 1] - m_prices[i][2]) 
bigest_discount = min(discount_prices_from_tickets)

print(min(total_min,bigest_discount))

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

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

print(result)

Submission status: Accepted

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

s = input()
a = [int(x) for x in list(s.split())]

s = input()
b = [int(x) for x in list(s.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())

amin = 10 ** 6
for aa in a:
    amin = min(amin,aa)
bmin = 10 ** 6
for bb in b:
    bmin = min(bmin,bb)

sum_min = amin + bmin

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

print(sum_min)

Submission status: Accepted

Solution code:
data = input().split(" ")
A = input().split(" ")
B = input().split(" ")
total = 1000000
a = 1000000
b = 1000000
j = 0
for i in data:
    data[j] = int(i)
    j += 1
j = 0
for i in A:
    A[j] = int(i)
    j += 1
j = 0
for i in B:
    B[j] = int(i)
    j += 1


for i in range(data[2]):
    data1 = input().split()
    j = 0
    for i in data1:
        data1[j] = int(i)
        j += 1
    data2 = A[data1[0]-1] + B[data1[1]-1] - data1[2]
    if total > data2:
        total = data2

for i in A:
    if a > i:
        a = i
for i in B:
    if b > i:
        b = i

if total > a+b:
    total = a+b

print(total)

Submission status: Accepted

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

al = input().split()
bl = input().split()
ml = [list(map(int, input().split())) for i in range(m)]

al = list(map(int, al))
bl = list(map(int, bl))

als = sorted(al)
bls = sorted(bl)

tmp = als[0] + bls[0]

comp = 0
fp = tmp
for i in ml:
  comp = al[i[0]-1] + bl[i[1]-1] - i[2]
  if comp < fp:
    fp = comp

print(fp)

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

m = []
am = min(a)
bm = min(b)

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

    m.append(a[x-1] + b[y-1] - z )



if am + bm > min(m):
    print(min(m))
else:
    print(am + bm)

Submission status: Accepted

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

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
Y = []
for i in range(M):
    X = list(map(int,input().split()))
    Y.append(int(a[X[0] - 1] + b[X[1] - 1] - X[2]))
Y.sort()
a.sort()
b.sort()

if Y[0] < a[0] + b[0]:
    print(Y[0])
else:
    print(a[0] + b[0])

Submission status: Accepted

Solution code:
A, B, M = map(int, input().split())
As = list(map(int,input().split()))
Bs = list(map(int,input().split()))
Ms = [input().split() for i in range(M)]

no_discount_min_plice = min(As) + min(Bs)

buy_list = [no_discount_min_plice]

for i in range(0, M):
    discount_plice = As[int(Ms[i][0])-1] + Bs[int(Ms[i][1])-1] - int(Ms[i][2])
    buy_list.append(discount_plice)

print(min(buy_list))

Submission status: Accepted

Solution code:
m=list(map(int, input().split()))
rei=list(map(int, input().split())) 
den=list(map(int, input().split())) 
cou = [0] * m[2]
ans = []
for i in range(m[2]):
	cou[i]=list(map(int, input().split()))
	ans.append(rei[cou[i][0]-1]+den[cou[i][1]-1]-cou[i][2])

ans.append(min(rei)+min(den))
print(min(ans))

Submission status: Accepted

Solution code:
(A, B, M) = (int(x) for x in input().split(' '))

#print(A, B, M)
ai = [int(x) for x in input().split(' ')]
bj = [int(x) for x in input().split(' ')]
ck = []
for k in range(int(M)):
  ck.append([int(x) for x in input().split(' ')])

amin = min(ai)
bmin = min(bj)
abmin = amin + bmin
#print(abmin)

for cupon in ck:
  ac = ai[cupon[0]-1]
  bc = bj[cupon[1]-1]
  cost = ac + bc - cupon[2]
#  print(cost)
  if cost < abmin:
    abmin = cost

print(abmin)

Submission status: Accepted

Solution code:
(R, D, M) = list(map(int, input().split()))
R_yen = list(map(int, input().split()))
D_yen = list(map(int, input().split()))
min = 100000000
min_R = 10000000
min_D = 10000000
for i in range(M):
  (R_dis, D_dis, Dis) = list(map(int, input().split()))
  a = R_dis-1
  b = D_dis-1
  k = R_yen[a] + D_yen[b] - Dis
  if min > k:
    min = k
for i in R_yen:
  if min_R > i:
    min_R = i
for i in D_yen:
  if min_D > i:
    min_D = i
if min > min_R + min_D:
  min = min_R + min_D
print(str(min))

Submission status: Accepted

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

la = list(map(int, input().split()))
lb = list(map(int, input().split()))

d = []
for i in range(M):
  d.append(list(map(int, input().split())))
           
for i in range(M):
  d[i] = la[(d[i][0]-1)] + lb[(d[i][1]-1)] - d[i][2]
  
o = min(la) + min(lb)
d.append(o)

print(min(d))

Submission status: Accepted

Solution code:
import sys

lines = sys.stdin.readlines()

# lines = test.strip().split('\n')
num_a ,num_b, num_m = [int(v) for v in lines[0].split()]
# ----

a_list = [int(v) for v in lines[1].split()[:num_a+1]]
b_list = [int(v) for v in lines[2].split()[:num_b+1]]

res1 = [
    a_list[a_i-1]+b_list[b_i-1]-discount for a_i, b_i, discount in [
        map(int, l.split())  for l in lines[3:num_m+3]
    ]
]

res2 = min(a_list) + min (b_list)

print(min(min(res1), res2))

Submission status: Accepted

Solution code:
import math

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

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

cur_best = min(a_list) + min(b_list)

for i in range(M):
    a_index,b_index,discount = map(int,input().split())
    
    price = a_list[a_index-1] + b_list[b_index-1] - discount
    
    cur_best = min(cur_best,price)
    
print(cur_best)

Submission status: Accepted

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

p = []
for i in range(M):
    s = input().split()
    p.append(int(a[int(s[0])-1])+int(b[int(s[1])-1])-int(s[2]))
p.append(low)
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()))
price1 = min(a) + min(b)

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

Submission status: Accepted

Solution code:
import sys

def main():
    input = sys.stdin.readline

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

    waribiki = [input().split() for _ in range(m)]
    
    res = [200000] * (m + 1)
    count = 0

    for i in range(m):
        res[count] = alist[int(waribiki[i][0])-1] + blist[int(waribiki[i][1])-1] - int(waribiki[i][2])
        count += 1

    res[count] = min(alist) + min(blist)
      
    print(min(res))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
frege_count, oven_count, coupon_count = map(int,input().split())	
frege_prices = list(map(int,input().split()))	
oven_prices = list(map(int,input().split()))	
coupon_list = [list(map(int, input().split())) for i in range(coupon_count)]

minprice = min(frege_prices) + min(oven_prices)
for coupon in coupon_list:
  total_cost = frege_prices[coupon[0]-1] + oven_prices[coupon[1]-1] - coupon[2]
  if minprice > total_cost:
          minprice = total_cost
print(minprice)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

a,b,m = [int(x) for x in input().split()]
al = [int(x) for x in input().split()]
bl = [int(x) for x in input().split()]
ml = []
for i in range(m):
    ml.append([int(x) for x in input().split()])

ans = min(al) + min(bl)

for i in range(m):
    tmp = al[ml[i][0]-1] + bl[ml[i][1]-1] - ml[i][2]
    if tmp < ans:
        ans = tmp

print(ans)

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()))
ans = min(A) + min(B)
for i in range(m):
    x, y, c = list(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())
val_m = [[0] * 3 for i in range(M)]

val_a = list(map(int, input().split()))
val_b = list(map(int, input().split()))

for i in range(M):
  val_m[i][0], val_m[i][1], val_m[i][2] = map(int, input().split())

dis_val = []
for i in range(M):
  dis_val.append(val_a[val_m[i][0]-1] + val_b[val_m[i][1]-1] - val_m[i][2])

val_a = list(set(val_a))
val_b = list(set(val_b))

val_a.sort()
val_b.sort()
dis_val.sort()

sum_val = val_a[0] + val_b[0]
if(sum_val <= dis_val[0]):
  print(sum_val)
else:
  print(dis_val[0])

Submission status: Accepted

Solution code:
a, b, m = input().split()
a, b, m = int(a), int(b), int(m)
a_values = input().split()
b_values = input().split()
m_values = {}
for i in range(m):
    m_values[i] = input().split()

min_num = int(a_values[int(m_values[0][0]) - 1]) + int(b_values[int(m_values[0][1]) - 1]) - int(m_values[0][2])
for i in range(1, m):
    now = int(a_values[int(m_values[i][0]) - 1]) + int(b_values[int(m_values[i][1]) - 1]) - int(m_values[i][2])
    if min_num > now:
        min_num = now
now = int(min(a_values)) + int(min(b_values))
if min_num > now:
    print(now)
else:
    print(min_num)

Submission status: Accepted

Solution code:
import sys

def load(vtype=int):
    return vtype(input().strip())


def load_list(seplator=" ", vtype=int):
    return [vtype(v) for v in input().strip().split(seplator)]

A, B, M = tuple(load_list())

a = load_list()
b = load_list()

coupon = dict()
for _ in range(0, M):
    x, y, c = tuple(load_list())
    if (x-1, y-1) in coupon:
        coupon[(x-1,y-1)] = max(coupon[(x-1,y-1)], c)
    else:        
        coupon[(x-1,y-1)] = c 

minv = min(a) + min(b)

for key in coupon.keys():
    i, j = key
    minv = min(minv, a[i] + b[j] - coupon[(i, j)])

print(minv)

Submission status: Accepted

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

ml = [input().split() for i in range(m)]

mp = min(al) + min(bl)
mpl = []

for i in range(m):
    aa = int(ml[i][0])
    bb = int(ml[i][1])

    mpl.append(int(al[aa - 1]) + int(bl[bb - 1]) - int(ml[i][2]))

print(min(mp, min(mpl)))

Submission status: Accepted

Solution code:
A,B,M = list(map(int, input().split()))
AP = list(map(int, input().split()))
BP = list(map(int, input().split()))
MC = list(input().split() for i in range(M))

#商品券なしパターン
TPX = min(AP)+min(BP)

#商品券ありパターン
TPY = 0
for i in range(M):
    TPZ = AP[int(MC[i][0])-1] + BP[int(MC[i][1])-1] - int(MC[i][2])
    if i == 0:
        TPY = TPZ
    else:
        if TPZ < TPY:
            TPY = TPZ
print(min(TPX,TPY))

Submission status: Accepted

Solution code:
A,B,M=map(int,input().split())
a=list(map(int,input().split()))
ad={}
for i in range(len(a)):ad[i]=a[i]
b=list(map(int,input().split()))
bd={}
for i in range(len(b)):bd[i]=b[i]
m=min(a)+min(b)
for _ in range(M):
    x,y,c=map(int,input().split())
    s=ad[x-1]+bd[y-1]-c
    m=min(m,s)
print(m)

Submission status: Accepted

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

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

m = [0] * M
x = [0] * M
y = [0] * M
for i in range (M):
    x[i], y[i], m[i] = map(int, input().split())
    

discount = [0] * M
for i in range(M):
    discount[i] = a[x[i]-1] + b[y[i]-1] - m[i]
    
    
discount_ab = min(a) + min (b)
if discount_ab > min(discount):
    print(min(discount))
else:
    print(discount_ab)

Submission status: Accepted

Solution code:
# coding: utf-8

import sys
import math
import collections
import itertools
from inspect import currentframe
INF = 10 ** 10
MOD = 10 ** 9 + 7
def input() : return sys.stdin.readline().strip()
def gcd(x, y) : return y if x % y == 0 else gcd(y, x % y)
def lcm(x, y) : return (x * y) // gcd(x, y)
def I() : return int(input())
def MI() : return map(int, input().split())
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(input()) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]
def chkprint(*args) : names = {id(v):k for k,v in currentframe().f_back.f_locals.items()}; print(', '.join(names.get(id(arg),'???')+' = '+repr(arg) for arg in args))

A, B, M = MI()
a = LI()
b = LI()
xyc = LRI(M)

ans = min(a) + min(b)

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

print(ans)

Submission status: Accepted

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

minimum_price_with_discount = 0

for i in range(M):
    x, y, c = (int(x) for x in input().split())
    price_with_discount = a_s[x-1] + b_s[y-1] - c
    if i == 0:
        minimum_price_with_discount = price_with_discount
    else:
        if minimum_price_with_discount > price_with_discount:
            minimum_price_with_discount = price_with_discount
        else:
            continue

a_s.sort(), b_s.sort()
minimum_price_without_discount = a_s[0] + b_s[0]

if minimum_price_with_discount > minimum_price_without_discount:
    print(minimum_price_without_discount)
else:
    print(minimum_price_with_discount)

Submission status: Accepted

Solution code:
a, b, m = map(int, input().split())
priceOfMicrowaves = list(map(int, input().split()))
priceOfRefrigerators = list(map(int, input().split()))
priceTable = [list(map(int,input().split())) for i in range(m)]
cheepest = priceOfMicrowaves[0] + priceOfRefrigerators[0]
for price in priceTable:
    if priceOfMicrowaves[price[0]-1]-price[2] >= cheepest:
        continue
    elif priceOfRefrigerators[price[1]-1]-price[2] >= cheepest:
        continue
    elif priceOfMicrowaves[price[0]-1]+priceOfRefrigerators[price[1]-1]-price[2] < cheepest:
        cheepest = priceOfMicrowaves[price[0]-1]+priceOfRefrigerators[price[1]-1]-price[2]
if cheepest > min(priceOfMicrowaves) + min(priceOfRefrigerators):
    cheepest = min(priceOfMicrowaves) + min(priceOfRefrigerators)
print(cheepest)

Submission status: Accepted

Solution code:
A, B, M = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
minimum = a[0]+b[0]

for k in range(M):
    x,y,c = map(int,input().split())
    tmp = a[x-1]+b[y-1]-c
    if minimum > tmp:
        minimum = tmp

a.sort()
b.sort()

for i in a:
    if i + b[0] > minimum:
        break
    for j in b:
        tmp = i + j
        if minimum > tmp:
            minimum = tmp
        else:
            break

print(minimum)

Submission status: Accepted

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

minimum_price_with_discount = 0

for i in range(M):
    x, y, c = (int(x) for x in input().split())
    price_with_discount = a_s[x-1] + b_s[y-1] - c
    if i == 0:
        minimum_price_with_discount = price_with_discount
    else:
        if minimum_price_with_discount > price_with_discount:
            minimum_price_with_discount = price_with_discount
        else:
            continue

a_s.sort(), b_s.sort()
minimum_price_without_discount = a_s[0] + b_s[0]

if minimum_price_with_discount > minimum_price_without_discount:
    print(minimum_price_without_discount)
else:
    print(minimum_price_with_discount)

Submission status: Accepted

Solution code:
inp = input().split(" ")
A=int(inp[0])
B=int(inp[1])
M=int(inp[2])

if A!=0:
    a=input().split(" ")
else:
    a=[0]
if B!=0:
    b=input().split(" ")
else:
    b=[0]

s=[0]*(M+(1))
m=[[0]*3]*M
i=0
for x in m:
    x=input().split(" ")
    s[i]=int(a[int(x[0])-1])+int(b[int(x[1])-1])-int(x[2])
    i+=1

s[i]=int(min(a))+int(min(b))

print(min(s))

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:
import numpy as np
A,B,M = map(int,input().rstrip().split())
a = list(map(int,input().rstrip().split()))
b = list(map(int,input().rstrip().split()))

minp = min(a) + min(b)

minpp = 10**6
for k in range(M):
  i,j,c = map(int,input().rstrip().split())
  minpp = min(a[i-1]+b[j-1]-c,minpp)

print(min(minp,minpp))

Submission status: Accepted

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

#割引なしの最小金額を設定
aSortedLst = sorted(aLst)
bSortedLst = sorted(bLst)
price = aSortedLst[0] + bSortedLst[0]

#割引を適応
for i in range(m):
    x, y, c = map(int, input().split())
    disPrice = aLst[x - 1] + bLst[y - 1] - c
    if disPrice < price:
        price = disPrice
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()))
s = [input().split() for i in range(M)]

mini = min(a) + min(b)

total = []
for i in s:
    total.append(a[int(i[0])-1]+b[int(i[1])-1]- int(i[-1]))
    
mini_2 = min(total)

if mini <= mini_2:
    print(mini)
else:
    print(mini_2)

Submission status: Accepted

Solution code:
a,b,m = list(map(int,input().split()))
arr = list(map(int,input().split()))
brr = list(map(int,input().split()))
l = []
for rep in range(m):
	x,y,c = list(map(int,input().split()))
	p = arr[x-1] + brr[y-1] - c
	l.append(p)
alt = min(arr) + min(brr)
print(min(min(l),alt))

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
for i in range(M):
  x[i],y[i],c[i] = map(int,input().split())
ans = 10**10
ma = max(c)
#ind = c.index(ma)
am = min(a)
bm = min(b)
mae = am + bm #ここまで
#indxy = a[x[ind]-1] + b[y[ind]-1] - ma

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

Submission status: Accepted

Solution code:
A,B,M=map(int,input().split())
vecA=list(map(int,input().split()))
vecB=list(map(int,input().split()))
matX=[input().split() for k in range(M)]
price = 10**6
for i in range(0,M):
    pricecom = int(vecA[int(matX[i][0]) -1]) + int(vecB[int(matX[i][1]) -1]) - int(matX[i][2])
    if pricecom<= price:
        price=pricecom
    else:
        pass
price2=int(min(vecA)) + int(min(vecB))
if price2<=price:
    price=price2
print(price)

Submission status: Accepted

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

f=list(map(int,input().split()))
r=list(map(int,input().split()))
    
ans=min(f)+min(r)

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

print(ans)

Submission status: Accepted

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

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

x = list()
y = list()
c = list()
for i in range(M):
    xi, yi, ci = map(int,input().split())
    x.append(xi)
    y.append(yi)
    c.append(ci)

p = list()

amin = min(a)
bmin = min(b)
pab  = amin + bmin
p.append(pab)
        
for i in range(M):
    pi = a[x[i]-1] + b[y[i]-1] - c[i]
    p.append(pi)

print(min(p))

Submission status: Accepted

Solution code:
A,B,M=map(int,input().split())
aList=list(map(int,input().split()))
bList=list(map(int,input().split()))
mab=min(aList)+min(bList)
for i in range(M):
  x,y,c=map(int,input().split())
  tt=aList[x-1]+bList[y-1]-c
  if mab > tt:
    mab=tt
print(mab)

Submission status: Accepted

Solution code:
#読み込み
list_num = input().split(" ") #A,B,M
list_ref = input().split(" ") #冷蔵庫の値段
list_ren = input().split(" ") #レンジの値段
list2 = [] #割引できるやつの組み
for i in range(int(list_num[2])):
    list_c = input().split(" ")
    list2.append(list_c)
A = int(list_num[0])
B = int(list_num[1])
M = int(list_num[2])

list_price = []

#一番安いのと一番安いの
list_ref_int = [int(s) for s in list_ref]
list_ren_int = [int(s) for s in list_ren]
cheap = min(list_ref_int) + min(list_ren_int)
list_price.append(cheap)

#割引きを総当たり
for k in range(M):
    price = list_ref_int[int(list2[k][0])-1] + list_ren_int[int(list2[k][1])-1] - int(int(list2[k][2])-1) - 1
    list_price.append(price)

print(min(list_price))

Submission status: Accepted

Solution code:
i = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
min_cost=min(a)+min(b)
for j in range(i[2]):
    x = list(map(int, input().split()))
    if (a[x[0]-1]+b[x[1]-1]-x[2])<min_cost:
        min_cost=(a[x[0]-1]+b[x[1]-1]-x[2])
print(min_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()))
m = [list(map(int,input().split())) for i in range(M)]
n = list()
#割引券なしの最小値
min_a = min(a)
min_b = min(b)
sa = min_a + min_b
n.append(sa)
#割引券使用時の最小値
for i in range(M):
    su = a[m[i][0]-1] + b[m[i][1]-1] - m[i][2]
    n.append(su)

#比較＆出力
ans = min(n)
print(ans)

Submission status: Accepted

Solution code:
listA=[] #appendのために宣言が必要
while True:
    try:
        listA.append(list(map(int,input().split())))

    except:
        break;
        #または、quit(),os.exit()をして止める。

con=min(listA[1])+min(listA[2])
listB=[listA[1][listA[i+3][0]-1]+listA[2][listA[i+3][1]-1]-listA[i+3][2] for i in range(listA[0][2])]
print(min(con,min(listB)))

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



ans=min(a)+min(b)



for i in range(M):

    if ans>a[x[i]-1]+b[y[i]-1]-c[i]:
        ans=a[x[i]-1]+b[y[i]-1]-c[i]

print(ans)

Submission status: Accepted

Solution code:
a, b, m = map(int, input().split())
ax = list(map(int, input().split()))
bx = list(map(int, input().split()))
x = []
for i in range(m):
    _x = map(int, input().split())
    x.append(list(_x))

min_a = min(ax)
min_b = min(bx)
min_sum = min_a + min_b

for k in x:
    sum = ax[k[0]-1] + bx[k[1]-1] - k[2]
    if sum < min_sum:
        min_sum = sum

print("{}".format(min_sum))

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()]
price_off = [dict(zip(["x", "y", "c"], map(int, input().split()))) for _ in range(M)]
result = [min(a) + min(b)]
result += [a[d["x"]-1] + b[d["y"]-1] - d["c"] for d in price_off]
print(min(result))

Submission status: Accepted

Solution code:

A,B,M = map(int, input().split())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
x = [list(map(int, input().split())) for _ in range(M)]
#print(A,B,M)
#print(a)
#print(b)
#print(x)

p = min(a) + min(b) #安いもの通しの組み合わせ
#print(p)
l=[]

for i in range(M):
    temp = a[x[i][0]-1] + b[x[i][1]-1] - x[i][2]
    l.append(temp)
#print(l)

print(min(p,min(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()))
m=[]
for i in range(M):
    m.append(input().split())

counta=0
countb=0
nummin=int(a[0])+int(b[0])
for i in m:
    
    x=int(i[0])-1
    y=int(i[1])-1
    c=int(i[2])
    num=a[x]+b[y]-c

    if num<nummin:
        nummin=num
if min(a)+min(b)<nummin:
    nummin=min(a)+min(b)

print(nummin)

Submission status: Accepted

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

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

mini = min(a)+ min(b)

def check(Mlist, mini):
    #print(Mlist)
    if mini > a[Mlist[0]-1]+b[Mlist[1]-1]-Mlist[2]:
        return a[Mlist[0]-1]+b[Mlist[1]-1]-Mlist[2]
    return mini
for i in range(M):
    mini = check(list(map(int,input().split())),mini)

print(mini)

Submission status: Accepted

Solution code:


a, b, m = map(int, input().split())
fridge = list(map(int, input().split()))
micro = list(map(int, input().split()))
c = []
for i in range(m):
    c.append(list(map(int, input().split())))
costs = []
for i in c:
    temp = fridge[i[0]-1]+micro[i[1]-1]-i[2]
    costs.append(temp)
fridge.sort()
micro.sort()
costs.append(fridge[0]+micro[0])
costs.sort()
print(costs[0])

Submission status: Accepted

Solution code:
A, B, M = map(int, input().split())
aList = list(map(int, input().split()))
bList = list(map(int, input().split()))
mList = [list(map(int, input().split())) for i in range(M)]
Min = 20001

Min = min(aList) + min(bList)
for i in range(M):
    cost = aList[mList[i][0] -1] + bList[mList[i][1] -1] - mList[i][2]
    Min = min(Min, cost)

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()))
mini =min(A_) + min(B_)
for i in range(M):
    array = list(map(int,input().split()))
    m = A_[array[0]-1] + B_[array[1]-1] -array[2]
    if(mini > m):
        mini = m
print(mini)

Submission status: Accepted

Solution code:
a, b, m = map(int, input().split())
pa = list(map(int, input().split()))
pb = list(map(int, input().split()))
xyc = [list(map(int, input().split())) for j in range(m)]
minprice = min(pa)+min(pb)
wari=0
for i in xyc:
    wari = pa[i[0]-1]+pb[i[1]-1]-i[2]
    if wari<minprice:
        minprice = wari
print(minprice)

Submission status: Accepted

Solution code:
def totalprice_with_discount_ticket(ref, mic, discount_ticket):
    totalprice = min(ref) + min(mic)
    for t in discount_ticket:
        discnt_ref_num = t[0] - 1
        discnt_mic_num = t[1] - 1
        discnt_amt = t[2]
        if totalprice > ref[discnt_ref_num] + mic[discnt_mic_num] - discnt_amt:
            totalprice = ref[discnt_ref_num] + mic[discnt_mic_num] - discnt_amt

    return totalprice


if __name__ == '__main__':
    ref_num, mic_num, ticket_num = map(int, input().split())
    ref_list = list(map(int, input().split()))
    mic_list = list(map(int, input().split()))
    discount_ticket_list = [list(map(int, input().split()))
                            for i in range(ticket_num)]
    print(totalprice_with_discount_ticket(
        ref_list, mic_list, discount_ticket_list))