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:
NA, NB, NM = (int(x) for x in input().split())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
M = [[int(x) for x in input().split()] for i in range(NM)]
res = min(A) + min(B)
for i in range(NM):
  x, y, c = M[i]
  res = min(res, A[x-1] + B[y-1] - c)
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()))
card = [list(map(int, input().split())) for _ in range(M)]

min_price = min(a) + min(b)

for C in card:
    x, y, c = C
    price = a[x - 1] + b[y - 1] - c
    if price < min_price:
        min_price = price
print(min_price)

Submission status: Accepted

Solution code:
A, B, M= [int(i) for i in input().split(' ')]
AA = [int(i) for i in input().split(' ')]
BB = [int(i) for i in input().split(' ')]

XYC = []
for _ in range(M):
    XYC.append([int(i) for i in input().split(' ')])

min_a , min_b = min(AA),min(BB)
min_ab = min_a + min_b

for x,y,c in XYC:
    cost = AA[x-1] + BB[y-1] - c
    min_ab = min(cost,min_ab)

print(min_ab)

Submission status: Accepted

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

small = min(a) + min(b)

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

print(small)

Submission status: Accepted

Solution code:
import sys
import heapq
import re
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from fractions import gcd
from math import factorial, sqrt
from functools import lru_cache, reduce
INF = 1 << 60
mod = 1000000007
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

# UnionFind
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

# ダイクストラ
def dijkstra_heap(s, edge, n):
    #始点sから各頂点への最短距離
    d = [10**20] * n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d

# 素因数分解
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

# 2数の最小公倍数
def lcm(x, y):
    return (x * y) // gcd(x, y)

# リストの要素の最小公倍数
def lcm_list(numbers):
    return reduce(lcm, numbers, 1)

# リストの要素の最大公約数
def gcd_list(numbers):
    return reduce(gcd, numbers)

# ここから書き始める
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 = min(A) + min(B)
i = 0
while i < m:
    x,y,c = map(int,input().split(' '))
    cost0 = A[x-1]+B[y-1]-c
    if cost0 < cost:
        cost = cost0
    i += 1
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()))
d = []
ans = a[0]+b[0]
for i in range(M):
    d.append(list(map(int,input().split())))
for i in range(M):
    x = a[d[i][0]-1] + b[d[i][1]-1] - d[i][2]
    if x < ans:
        ans = x
a.sort()
b.sort()
print(min(a[0]+b[0],ans))

Submission status: Accepted

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

refrigerator = list(map(int, input().split()))
oven = list(map(int, input().split()))
coupon = [list(map(int, input().split())) for i in range(m)]

normal = min(refrigerator) + min(oven)
ans = normal

tmp = 0


for i in range(m):
  tmp = refrigerator[coupon[i][0]-1]+oven[coupon[i][1]-1]-coupon[i][2]
  if ans > tmp:
    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()))
x_y_c = [list(map(int, input().split())) for i in range(M)]

cost_min = min(a) + min(b)
for i in range(M):
    x, y, c = x_y_c[i]
    cost = a[x-1] + b[y-1] - c
    cost_min = min(cost_min, cost)
print(cost_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()))

min_sum = min(A) + min(B)

M = []
for i in range(m):
      an, bn, diff = list(map(int, input().split()))
      M.append(A[an - 1] + B[bn - 1] - diff)

diff_min = min(M)
print(min_sum if min_sum < diff_min else diff_min)

Submission status: Accepted

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

# no discount
min_val = min(a) + min(b)
# with discount
for ai, bi, ci in m:
    val = a[ai-1] + b[bi-1] - ci
    if min_val > val:
        min_val = val
print(min_val)

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

# no discount
min_val = min(a) + min(b)
# with discount
for ai, bi, ci in m:
    val = a[ai-1] +b[bi-1] -ci
    if min_val > val:
        min_val = val
print(min_val)

Submission status: Accepted

Solution code:
def main():
    _, _, 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()))
m=[]
for i in range(M):
    array = list(map(int, input().strip().split()))
    m.append(array)

def hitachi02(a,b,m):
    results=[]
    cal01=min(a)+min(b)
    for k in range(len(m)):
        results.append(a[m[k][0]-1]+b[m[k][1]-1]-m[k][2])
    cal02=min(results)
    if cal01>=cal02:
        return cal02
    else:
        return cal01

result=hitachi02(a,b,m)
print(result)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
''' ===========================================
from collections import deque
    appendleft() = push_front(), append = push_back()
    popfleft() = pop_front(), pop() = pop_back()
import heapq #heappush(trgt, val) heappop(trgt) trgt[0] __lt__<
=========================================== '''
##======================================python3
import sys
import collections
sys.setrecursionlimit(10**6)

class gv:
    A, B, M = [0,0,0]
    renzi = []
    reizo = []
    
def build():
    gv.A, gv.B, gv.M = map(int, sys.stdin.readline().split(' '))
    *gv.renzi, = map(int, input().split())
    *gv.reizo, = map(int, input().split())

def solve():
    ans = min(gv.renzi) + min(gv.reizo)
    
    for i in range(gv.M):
        rx, ry, rc = map(int, input().split())
        
        ans_buf = gv.renzi[rx -1] + gv.reizo[ry -1] - rc
        ans = min(ans, ans_buf)
    
    print(ans)

if __name__ == '__main__':
    build()
    solve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import pprint

def buy():

    num_refrigerator, num_microwave, num_coupon = map(
        lambda x : int(x), input().split(" ")
    )

    price_list_refrigerator = list(map(lambda x : int(x), input().split(" ")))
    price_list_microwave = list(map(lambda x : int(x), input().split(" ")))

    coupon_list = []
    for _ in range(num_coupon):
        coupon_list.append(list(map(lambda x : int(x), input().split(" "))))

    # get price of most low price refrigerator and microwave.
    least_price = min(price_list_refrigerator) + min(price_list_microwave)

    for product in coupon_list:
        use_coupon_price = (price_list_refrigerator[product[0] - 1]
                        + price_list_microwave[product[1] - 1]
                        - product[2])
        if(least_price > use_coupon_price):
            least_price = use_coupon_price

    print(least_price)


if __name__ == "__main__":
    buy()

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

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

ans = min(a_li) + min(b_li)

for i in range(m):
    a_num = sum_li[i][0]
    b_num = sum_li[i][1]
    waribiki = sum_li[i][2]
    
    a_place = a_li[a_num-1]
    b_place = b_li[b_num-1]
    
    ans = min(ans, a_place + b_place - waribiki)
    
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:
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))
a,b,m = iim()
A = iil()
B = iil()
ans = min(A)+min(B)

for i in range(m):
    x,y,c = iim()
    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_prices=[int(i) for i in input().split()]
b_prices=[int(i) for i in input().split()]
a_min=min(a_prices)
b_min=min(b_prices)
a_add_b=a_min+b_min
for i in range(m):
    x,y,c=map(int,input().split())
    if a_prices[x-1]+b_prices[y-1]-c<a_add_b:
        a_add_b=a_prices[x-1]+b_prices[y-1]-c
print(a_add_b)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

a,b,m=mii()
arra=limii()
arrb=limii()

ans=min(arra)+min(arrb)

for i in range(m):
    x,y,c=mii()
    ans = min(ans, arra[x-1]+arrb[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()))
x = [0]*M
y = [0]*M
c = [0]*M
for i in range(M):
    x[i], y[i], c[i] = map(int, input().split())
price = min(a) + min(b)
for j in range(M):
    cprice = a[x[j]-1] + b[y[j]-1] - c[j]
    if cprice < price:
        price = cprice
print(price)

Submission status: Accepted

Solution code:
A, B, M = map(int, input().split())
*a, = map(int, input().split())
*b, = map(int, input().split())
x, y, c = [], [], []
for _ in range(M):
    xa, ya, ca = map(int, input().split())
    x += [xa]; y += [ya]; c += [ca]
mi = min(a[x[i]-1] + b[y[i]-1] - c[i] for i in range(M))
print(min(mi, 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()))
discount = [list(map(int, input().split())) for _ in range(M)]
ans = min(a) + min(b)

for i in range(M):
    tmp = a[discount[i][0]-1] + b[discount[i][1]-1] - discount[i][2]
    if  tmp < ans:
        ans = tmp

print(ans)

Submission status: Accepted

Solution code:
## coding: UTF-8
from decimal import *
from itertools import permutations, combinations,combinations_with_replacement,product

s = input().split()
t = [int(p) for p in s]

A = t[0]
B = t[1]
M = t[2]

s = input().split()
t = [int(p) for p in s]

a = t

s = input().split()
t = [int(p) for p in s]

b = t

discount = []
for i in range(M):
    s = input().split()
    t = [int(p) for p in s]
    discount.append(t)


price = [min(a) + min(b)]

for i in range(len(discount)):
    price.append( a[discount[i][0] - 1] + b[discount[i][1] - 1] - discount[i][2])


#print('A:{}, B:{}, M:{}, a:{}, b:{}, discount:{}'.format(A,B,M,a,b,discount))
#print(price)
print(min(price))

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()]
l = []
for i in range(M):
    l.append([int(i) for i in input().split()])

cand = [min(a)+min(b)]
for i in range(M):
    if l[i][0]-1<A and l[i][1]-1<B:
        cand.append(a[l[i][0]-1]+b[l[i][1]-1]-l[i][2])

print(min(cand))

Submission status: Accepted

Solution code:
a,b,m = map(int,input().split(" "))
ar = list(map(int,input().split(" ")))
br = list(map(int,input().split(" ")))
A = min(ar) + min(br)
for i in range(m):
    l = list(map(int,input().split(" ")))
    B = (ar[l[0]-1] + br[l[1]-1]) - l[2]
    if A > B:
        A = B
print(A)

Submission status: Accepted

Solution code:
A,B,M=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
vch=[]
ac=10**15
for i in range(A):
    ac=min(ac,a[i])
bc=10**15
for i in range(B):
    bc=min(bc,b[i])
ans=ac+bc
for i in range(M):
    c=list(map(int,input().split()))
    ans=min(ans,a[c[0]-1]+b[c[1]-1]-c[2])
print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10000000)
from collections import defaultdict
from bisect import *
mod = 10**9+7

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

Submission status: Accepted

Solution code:
A,B,M = list(map(int, input().split()))
AL = list(map(int, input().split()))
BL = list(map(int, input().split()))
#L = []
ans = min(AL) + min(BL)
for _ in range(M):
  x,y,c = list(map(int, input().split()))
  x,y = x-1, y-1
  ans = min(ans, AL[x] + BL[y] - c)
  
print(ans)

Submission status: Accepted

Solution code:
r_cnt,d_cnt,w_cnt = map(int, input().split())
rei = list(map(int, input().split()))
den = list(map(int, input().split()))
wari = []
min_amount = 0
for i in range(w_cnt):
    a,b,c = map(int, input().split())
    amount = rei[a - 1] + den[b - 1] - c
    if i == 0 or amount < min_amount:
        min_amount = amount

amount = min(rei) + min(den)
if amount < min_amount:
    min_amount = amount
print(min_amount)

Submission status: Accepted

Solution code:
import sys
a,b,m = map(int,input().split())
ai = list(map(int,input().split()))
bj = list(map(int,input().split()))
#xyc =[]
#for i in range(m):
#    xyc.append(list(map(int,input().split())))
an = min(ai)+min(bj)
for i in range(m):
    x,y,c = map(int,input().split())
    an = min(an,ai[x-1]+bj[y-1]-c)
print(an)

Submission status: Accepted

Solution code:
S = [int(e) for e in input().split()]
list_a =  [int(e) for e in input().split()]
list_b =  [int(e) for e in input().split()]

dis_list = []

for i in range(S[2]):
    dis_list.append([int(e) for e in input().split()])

min_num1 = min(list_a) + min(list_b)

min_num2_list = []

for l in dis_list:
    min_num2_list.append(list_a[l[0]-1] + list_b[l[1]-1] - l[2])

min_num2 = min(min_num2_list)

if min_num1 > min_num2:
    print(min_num2)
else:
    print(min_num1)

Submission status: Accepted

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

mx = min(aa) + min(bb) # 割引なしの最安
for i in range(m):
    x, y, c = xyc[i]
    x -= 1
    y -= 1
    mx = min(mx, aa[x]+bb[y]-c)
print(mx)

Submission status: Accepted

Solution code:
A, B, M = input().split()
a_num = input()
b_num = input()
number = [input() for i in range(int(M))]

a_cost = []
b_cost = []

for a in a_num.split():
	a_cost.append(a)

for b in b_num.split():
    b_cost.append(b)


cal_box = []
# 番号が入る　冷蔵庫と電子レンジの組み合わせ
for i in range(int(M)):
    x, y, c = number[i].split()
        
    cal = int(a_cost[int(x)-1]) + int(b_cost[int(y)-1]) - int(c)
    cal_box.append(cal)

cal_box.append(int(min(a_cost)) + int(min(b_cost)))

print(int(min(cal_box)))

Submission status: Accepted

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

for k in range(M):
  x = dis[k][0] - 1
  y = dis[k][1] - 1
  c = dis[k][2]
  discount = a[x] + b[y] - c
  total.append(discount)
  
  
print(min(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()))
c = [list(map(int,input().split())) for _ in range(M)]
ans = min(a) + min(b)

for i in range(M):
  x = a[c[i][0]-1] + b[c[i][1]-1] - c[i][2]
  if ans >= x:
    ans = x
print(ans)

Submission status: Accepted

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

min_a = min(a)
min_b = min(b)
min_std = min_a + min_b
#print(f'最小値：{min_std}')
work = []
cnt = 0
while True:
    cnt += 1
    work.append([int(i) for i in input().split()])
    #print(cnt)
    if cnt == M:
        break
waribiki_list = []
for xyc in work:
    x, y ,c = xyc[0], xyc[1], xyc[2]
    #print(x, y, c)
    waribiki_list.append(a[x-1] + b[y-1] - c)

#print(f'割引の最小値：{min(waribiki_list)}')
if min_std > min(waribiki_list):
    print(min(waribiki_list))
else:
    print(min_std)

Submission status: Accepted

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

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

total = [0] * M

#　割引のMAXを求める
# dct = sorted(c, reverse=True)
# p rint(dct)

for k in range(M):
        # 割引パターン
        total[k] = (PA[x[k]-1] + PB[y[k]-1]) - c[k]

# なしパターン
ntotal = min(PA) + min(PB)
# ありパターン
ytotal = min(total)

if ntotal > ytotal:
        print(ytotal)
else:
        print(ntotal)

Submission status: Accepted

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

ans = min(a)+min(b)

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

print(ans)

Submission status: Accepted

Solution code:
A,B,M = map(int, input().split())
a = 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())


#  A種類の冷蔵庫とB種類の電子レンジ
 
cost = 10**25
for i in range (M):
    reizouko = x[i]-1
    densirenge = y[i]-1
    nedan = ((a[reizouko] + b[densirenge]) - c[i])
    
    if nedan <= cost:
        cost = nedan

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

Submission status: Accepted

Solution code:
#template
from collections import Counter
def inputlist(): return [int(i) for i in input().split()]
#template
A,B,M = inputlist()
a = inputlist()
b = inputlist()
ma = sorted(a)[0]
mb = sorted(b)[0]
mc = ma+mb
for i in range(M):
    x,y,c = inputlist()
    x -=1
    y -=1
    mc = min(mc,a[x]+b[y]-c)
print(mc)

Submission status: Accepted

Solution code:
#template
from sys import setrecursionlimit
setrecursionlimit(10**6)
from collections import Counter
def inputlist(): return [int(i) for i in input().split()]
#template
A,B,M = inputlist()
a = inputlist()
b = inputlist()
ma = sorted(a)[0]
mb = sorted(b)[0]
mc = ma+mb
for i in range(M):
    x,y,c = inputlist()
    x -=1
    y -=1
    mc = min(mc,a[x]+b[y]-c)
print(mc)

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)]
tmp = min(A) + min(B)
tmp1 = 100000000
for i in range(m):
    aa = xyc[i][0] - 1
    bb = xyc[i][1] - 1
    tmp1 = min(A[aa] + B[bb] - xyc[i][2], tmp1)

print(min(tmp, tmp1))

Submission status: Accepted

Solution code:
import copy
A,B,M = (int(x) for x in input().split())
a = list()
b = list()
x = list()
y = list()
c = list()
for j in input().split():
    a.append(int(j))

for j in input().split():
    b.append(int(j))
    
for i in range(M):
    tx,ty,tc = (int(j) for j in input().split())
    x.append(int(tx))
    y.append(int(ty))
    c.append(int(tc))

pat=0
mini = 200000
ca = copy.copy(a)
cb = copy.copy(b)
a.sort()
b.sort()

mini = a[0] + b[0]

#for i in range(len(a)):
#    for j in range(len(b)):
#        pat = a[i] + b[j]
#        if mini > pat:
#            mini = pat
for i in range(M):
    pat = ca[x[i]-1] + cb[y[i]-1] - c[i]
    if mini > pat:
        mini = pat

print(mini)

Submission status: Accepted

Solution code:
# A = [list(map(int, input().split())) for _ in range(3)]
# k = int(input())
# B = [int(input()) for _ in range(n)]
# X = list(map(int, input().split()))
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = []
for _ in range(M):
    x, y, c = map(int, input().split())
    total = a[x-1] + b[y-1] - c
    ans.append(total)
ans.append(min(a)+min(b))
print(min(ans))

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
A, B, M = map(int, input().split())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
P = [list(map(int,input().split())) for i in range(M)]

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

print(ans)

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()
sys.setrecursionlimit(10 ** 7)

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())
    now = a[x-1] + b[y-1] - c
    ans = min(ans, now)
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()))
dis=float('inf')
for i in range(M):
    x,y,c=map(int,input().split())
    dis=min(dis,a[x-1]+b[y-1]-c)
ans=min(min(a)+min(b),dis)
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()))
ret = min(a) + min(b)
for m in range(M):
  x, y, c = map(int, input().split())
  ret = min(ret, a[x-1]+b[y-1]-c)
print(ret)

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

Submission status: Accepted

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

amin = min(A)
bmin = min(B)
smin = amin + bmin

for i in range(m):
  x, y, c= map(int, input().split())
  th = smin + c
  apmin = A[x-1]
  if apmin > th:
    pass
  else:
    bpmin = B[y-1]
    spmin = apmin + bpmin -c
    if spmin < smin:
      smin = spmin
    else:
      pass
print(smin)

Submission status: Accepted

Solution code:
#h=int(input())
a,b,m=map(int,input().split())
al=list(map(int,input().split()))
bl=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]

ans=min(al)+min(bl)

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

print(ans)

Submission status: Accepted

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

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

min_price = min(a_list) + min(b_list)

for discount in discount_list:
    min_price = min(min_price,a_list[discount[0]-1]+b_list[discount[1]-1]-discount[2])

print(min_price)

Submission status: Accepted

Solution code:
import cmath
import sys

INF=10**18
MOD=10**9+7
MAX=10**5+7



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 i in range(M):
    x,y,c=map(int, input().split())
    x-=1
    y-=1
    ans=min(ans, a[x]+b[y]-c)
  
  print(ans)
  
  
if __name__=='__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

ans = min(a) + min(b)

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

Submission status: Accepted

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

al = [int(i) for i in input().split()]
bl = [int(i) for i in input().split()]

ans = min(al) + min(bl)

for i in range(m):
    ai,bi,ci = [int(i) for i in input().split()]
    ans = min(ans,al[ai-1] + bl[bi-1] - ci)
    
print(ans)

Submission status: Accepted

Solution code:
A, B, M = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
x, y, c = [[], [], []]
for i in range(M):
    inp = input().split()
    x.append(int(inp[0]))
    y.append(int(inp[1]))
    c.append(int(inp[2]))
mi = min(a) + min(b)
for i in range(M):
    waribiki = a[x[i]-1] + b[y[i]-1] - c[i]
    if waribiki < mi:
        mi = waribiki
print(mi)

Submission status: Accepted

Solution code:
_, _, M = map(int, input().split())
# price list
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
# min price
min_price = min(a_list) + min(b_list)
for _ in range(M):
  x, y, c = map(int, input().split())
  discount_price = a_list[x-1] + b_list[y-1] - c
  min_price = min(min_price, discount_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()))
l=[[int(i) for i in input().split()] for j in range(M)]
m=min(a)+min(b)
for x in l:
    m=min(m,a[x[0]-1]+b[x[1]-1]-x[2])
print(m)