Problem:


Score : 200 points

Problem Statement

You are visiting a large electronics store to buy a refrigerator and a microwave.

The store sells A kinds of refrigerators and B kinds of microwaves. The i-th refrigerator ( 1 \le i \le A ) is sold at a_i yen (the currency of Japan), and the j-th microwave ( 1 \le j \le B ) is sold at b_j yen.

You have M discount tickets. With the i-th ticket ( 1 \le i \le M ), you can get a discount of c_i yen from the total price when buying the x_i-th refrigerator and the y_i-th microwave together. Only one ticket can be used at a time.

You are planning to buy one refrigerator and one microwave. Find the minimum amount of money required.

Constraints

All values in input are integers.

 1 \le A \le 10^5 

 1 \le B \le 10^5 

 1 \le M \le 10^5 

 1 \le a_i , b_i , c_i \le 10^5 

 1 \le x_i \le A 

 1 \le y_i \le B 

 c_i \le a_{x_i} + b_{y_i} 

Input

Input is given from Standard Input in the following format:

A B M
a_1 a_2 ... a_A
b_1 b_2 ... b_B
x_1 y_1 c_1
\vdots
x_M y_M c_M

Output

Print the answer.

Sample Input 1

2 3 1
3 3
3 3 3
1 2 1

Sample Output 1

5

With the ticket, you can get the 1-st refrigerator and the 2-nd microwave for 3+3-1=5 yen.

Sample Input 2

1 1 2
10
10
1 1 5
1 1 10

Sample Output 2

10

Note that you cannot use more than one ticket at a time.

Sample Input 3

2 2 1
3 5
3 5
2 2 2

Sample Output 3

6

You can get the 1-st refrigerator and the 1-st microwave for 6 yen, which is the minimum amount to pay in this case.
Note that using a ticket is optional.



Sample input:
2 3 1
3 3
3 3 3
1 2 1


Sample output:
5

Submission status: Accepted

Solution code:
a,b,m = map(int, input().split())
A = list(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())
    p = A[x-1] + B[y-1] - c
    if p < ans:
        ans = p
print(ans)

Submission status: Accepted

Solution code:
A, B, M = map(int, input().split())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
ans = min(a) + min(b)
for _ 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:
import sys
# input = sys.stdin.readline

def readlines(n):
    for _ in range(n):
        x, y, c = map(int, input().split())
        yield x-1, y-1, c

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

    yield(min(a) + min(b))

    for x, y, c in readlines(M):
        a_ = a[x]
        b_ = b[y]

        yield a_ + b_ - c

print(min(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()))
kingaku=[]
for i in range(M):
    x_input, y_input, c_input = map(int, input().split())
    kingaku.append(a[x_input-1]+b[y_input-1]-c_input)
kingaku.append(min(a)+min(b))

print(min(kingaku))

Submission status: Accepted

Solution code:
import sys

A, B, M = map(int, sys.stdin.readline().rstrip().split())
a = list(map(int, sys.stdin.readline().rstrip().split()))
b = list(map(int, sys.stdin.readline().rstrip().split()))
xyc = [list(map(int, sys.stdin.readline().rstrip().split())) for i in range(M)]
ans = min(a) + min(b)

for xyci in xyc:
    x, y, c = xyci
    tmp = a[x - 1] + b[y - 1] - c
    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()))
l=[]
for i in range(m):
  x,y,c=map(int,input().split())
  l.append(a[x-1]+b[y-1]-c)
l.append(min(a)+min(b))
print(min(l))

Submission status: Accepted

Solution code:
AA, BB, M = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
res = min(A) + min(B)
for i in range(M):
  x, y, c = list(map(int, input().split()))
  x-=1
  y-=1
  discount = A[x] + B[y] - c
  if discount < res:
    res = discount

print(res)

Submission status: Accepted

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

min_price = min(a_p) + min(b_p)

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

Submission status: Accepted

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

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

ans = min(a) + min(b)

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

print(ans)

Submission status: Accepted

Solution code:
A,B,m=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
a_min=min(a)
b_min=min(b)
discount_m=10000000
for i in range(m):
    x,y,c=map(int,input().split())
    p=a[x-1]+b[y-1]-c
    if p<discount_m:
        discount_m=p
print(min(a_min+b_min,discount_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()))
xyc = [list(map(int, input().split())) for _ in range(m)]

aMin = min(a)
bMin = min(b)
ans = aMin + bMin

for xycm in xyc:
    x = xycm[0] - 1
    y = xycm[1] - 1
    c = xycm[2]
    p = a[x] + b[y] - c

    if p < ans:
        ans = 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()))

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

# 割引券を使わない
m = min(a) + min(b)
ans = []
ans.append(m)
for i in range(M):
    x = L[i][0]
    y = L[i][1]
    c = L[i][2]
    p = a[x - 1]
    k = b[y - 1]
    ans.append(p + k - c)

print(min(ans))

Submission status: Accepted

Solution code:
A,B,M=map(int,input().split(" "))
As=list(map(int,input().split(" ")))
Bs=list(map(int,input().split(" ")))
ans=min(As)+min(Bs)
for i in range(M):
  x,y,c=map(int,input().split(" "))
  ans=min(ans,As[x-1]+Bs[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()))
aa=sorted(a)
bb=sorted(b)
ans=aa[0]+bb[0]
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()))

xyc = [map(int, input().split()) for _ in range(M)]
x, y, c = [list(i) for i in zip(*xyc)]

price1 = min(a) + min(b)
price2 = []

for i in range(M):
  xi = x[i] - 1
  yi = y[i] - 1
  price_tmp = a[xi] + b[yi] - c[i]
  price2.append(price_tmp)
  
price2 = min(price2)

if price1 > price2:
  print(price2)
else:
  print(price1)

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/hitachi2020/tasks/hitachi2020_b
a, b, m = map(int, input().split())

A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]

ans = float('inf')
for _ in range(m):
    x, y, c = map(int, input().split())
    x -= 1
    y -= 1
    t = A[x] + B[y] - c
    ans = min(ans, t)

MIN = min(A) + min(B)
ans = min(ans, MIN)
print(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()))
min_cost = min(a_list) + min(b_list)
for i 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_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))

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

total_min = min(a_list) + min(b_list)
for x,y,c in xyc_list:
    total = a_list[x-1] + b_list[y-1] - c
    if total_min > total:
        total_min = total

print(total_min)

Submission status: Accepted

Solution code:


A,B,M = map(int, input().split())
a = [int(x) for x in input().split()]
b = [int(y) for y in input().split()]
c = [[0 for k in range(3)] for k in range(M)]

m = 0
while m < M:
    c[m][0],c[m][1],c[m][2]= map(int, input().split())
    m = m + 1

result = min(a) + min(b)

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

print(result)

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

A, B, M = MAP()
a = LIST()
b = LIST()
xyc = [LIST() for _ in range(M)]

sum = [min(a)+min(b)]
for i in range(M):
	sum.append(a[xyc[i][0]-1] + b[xyc[i][1]-1] - xyc[i][2])

print(min(sum))

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

a, b, m = map(int, readline().split())
aa = list(map(int, readline().split()))
bb = list(map(int, readline().split()))
xyc = [list(map(int, readline().split())) for _ in range(m)]
ans = float('inf')
for x, y, c in xyc:
    ans = min(aa[x - 1] + bb[y - 1] - c, ans)
aa.sort()
bb.sort()
print(min(ans, aa[0] + bb[0]))

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

mins = min(a) + min(b)
for i in range(M):
  ai, bi, ci = c[i]
  mins = min(mins, a[ai-1] + b[bi-1] - ci)
print(mins)

Submission status: Accepted

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

price=[0]*(M+1)
price[0]=min(a)+min(b)

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

print(min(price))

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
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
d=[]
for i in range(m):
 x[i],y[i],c[i]=map(int,input().split())
 d.append(a[x[i]-1]+b[y[i]-1]-c[i])
print(min(min(d),min(a)+min(b)))

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()))
x_li=[list(map(int,input().split())) for _ in range(m)]
minprice = min(a_li) + min(b_li)
for i in x_li:
    price = a_li[i[0]-1] + b_li[i[1]-1] - i[2]
    minprice = min(minprice,price)
print(minprice)

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

ans = min(a) + min(b)

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

print(ans)

Submission status: Accepted

Solution code:
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
L = [[int(x) for x in input().split()] for _ in range(M)]

reg = min(a) + min(b)
for x, y, c in L:
    tmp = a[x-1] + b[y-1] - c
    reg = min(reg, tmp)
print(reg)

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

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    a,b,m=map(int,input().split())
    A=[int(_) for _ in input().split()]
    B=[int(_) for _ 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)

if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
a,b,m = map(int,input().split())
a_inputs = [int(i) for i in input().split()]
b_inputs = [int(i) for i in input().split()]
x_inputs = [[int(j) for j in input().split()]for i in range(m)]

ans = min(a_inputs)+min(b_inputs)

for xyc in x_inputs:
    cost = a_inputs[xyc[0]-1]+b_inputs[xyc[1]-1]-xyc[2]
    if cost<ans:
        ans= cost
print(ans)

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()))
min_cost = min(a_li) + min(b_li)

for i in range(M):
    x, y, discount = list(map(int, input().split()))
    a_idx = x - 1
    b_idx = y - 1
    cost = a_li[a_idx] + b_li[b_idx] - discount
    min_cost = min(min_cost, cost)

print(min_cost)

Submission status: Accepted

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

ans = min(a)+min(b)

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


yes_m = a[xyc[0][0]-1]+b[xyc[0][1]-1] - xyc[0][2]

for i in range(1,m):
    if yes_m > a[xyc[i][0]-1]+b[xyc[i][1]-1] - xyc[i][2]:
        yes_m = a[xyc[i][0]-1]+b[xyc[i][1]-1] - xyc[i][2]

no_m = min(a)+min(b)

print(min(no_m,yes_m))

Submission status: Accepted

Solution code:
A,B,M=list(int(i) for i in input().split())
acost=list(int(i) for i in input().split())
bcost=list(int(i) for i in input().split())
mina=min(acost)
minb=min(bcost)
amount=10**19+1
for _ in range(M):
    x,y,c=list(int(i) for i in input().split())
    if (acost[x-1]+bcost[y-1]-c)<amount:
        amount=acost[x-1]+bcost[y-1]-c
if amount<=(mina+minb):
    print(amount)
else:
    print(mina+minb)

Submission status: Accepted

Solution code:
# coding: utf-8
import re
import math
import itertools
from copy import deepcopy
import random
from heapq import heappop,heappush
import time
import os
import queue
import sys
import datetime
from functools import lru_cache
readline=sys.stdin.readline
sys.setrecursionlimit(2000)
#import numpy as np
alphabet="abcdefghijklmnopqrstuvwxyz"
mod=int(10**9+7)
inf=int(10**20)
week=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]
def yn(b):
    if b:
        print("yes")
    else:
        print("no")
def Yn(b):
    if b:
        print("Yes")
    else:
        print("No")
def YN(b):
    if b:
        print("YES")
    else:
        print("NO")
class union_find():
    def __init__(self,n):
        self.n=n
        self.P=[a for a in range(N)]
        self.rank=[0]*n
 
    def find(self,x):
        if(x!=self.P[x]):self.P[x]=self.find(self.P[x])
        return self.P[x]
 
    def same(self,x,y):
        return self.find(x)==self.find(y)
 
    def link(self,x,y):
        if self.rank[x]<self.rank[y]:
            self.P[x]=y
        elif self.rank[y]<self.rank[x]:
            self.P[y]=x
        else:
            self.P[x]=y
            self.rank[y]+=1
 
    def unite(self,x,y):
        self.link(self.find(x),self.find(y))
 
    def size(self):
        S=set()
        for a in range(self.n):
            S.add(self.find(a))
        return len(S)
def is_power(a,b):#aはbの累乗数か
    now=b
    while now<a:
        now*=b
    if now==a:return True
    else:return False
def bin_(num,size):
    A=[0]*size
    for a in range(size):
        if (num>>(size-a-1))&1==1:
            A[a]=1
        else:
            A[a]=0
    return A
def facs(n,mod_=0):
    A=[1]*(n+1)
    for a in range(2,len(A)):
        A[a]=A[a-1]*a
        if(mod_>0):A[a]%=mod_
    return A
def comb(n,r,mod_,fac):
    if(n-r<0):return 0
    return (fac[n]*pow(fac[n-r],mod_-2,mod_)*pow(fac[r],mod_-2,mod_))%mod_
def next_comb(num,size):
    x=num&(-num)
    y=num+x
    z=num&(~y)
    z//=x
    z=z>>1
    num=(y|z)
    if(num>=(1<<size)):return False
    else:
        return num
def get_primes(n,type="int"):
    A=[True]*(n+1)
    A[0]=False
    A[1]=False
    for a in range(2,n+1):
        if A[a]:
            for b in range(a*2,n+1,a):
                A[b]=False
    if(type=="bool"):return A
    B=[]
    for a in range(n+1):
        if(A[a]):B.append(a)
    return B
def is_prime(num):
    if(num<=2):return False
    i=2
    while i*i<=num:
       if(num%i==0):return False
       i+=1
    return True
def ifelse(a,b,c):
    if a:return b
    else:return  c
def join(A,c=" "):
    n=len(A)
    A=list(map(str,A))
    s=""
    for a in range(n):
        s+=A[a]
        if(a<n-1):s+=c
    return s
def factorize(n,type_="dict"):
    b = 2
    list_ = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            list_.append(b)
        b+=1
    if n > 1:list_.append(n)
    if type_=="dict":
        dic={}
        for a in list_:
            if a in dic:
                dic[a]+=1
            else:
                dic[a]=1
        return dic
    elif type_=="list":
        return list_
    else:
        return None
def floor_(n,x=1):
    return x*(n//x)
def ceil_(n,x=1):
    return x*((n+x-1)//x)
#################################### ########
# coding: utf-8
import re
import math
import itertools
from copy import deepcopy
import random
from heapq import heappop,heappush
import time
import os
import queue
import sys
import datetime
from functools import lru_cache
readline=sys.stdin.readline
sys.setrecursionlimit(2000)
#import numpy as np
alphabet="abcdefghijklmnopqrstuvwxyz"
mod=int(10**9+7)
inf=int(10**20)
def yn(b):
    if b:
        print("yes")
    else:
        print("no")
def Yn(b):
    if b:
        print("Yes")
    else:
        print("No")
def YN(b):
    if b:
        print("YES")
    else:
        print("NO")
class union_find():
    def __init__(self,n):
        self.n=n
        self.P=[a for a in range(N)]
        self.rank=[0]*n
 
    def find(self,x):
        if(x!=self.P[x]):self.P[x]=self.find(self.P[x])
        return self.P[x]
 
    def same(self,x,y):
        return self.find(x)==self.find(y)
 
    def link(self,x,y):
        if self.rank[x]<self.rank[y]:
            self.P[x]=y
        elif self.rank[y]<self.rank[x]:
            self.P[y]=x
        else:
            self.P[x]=y
            self.rank[y]+=1
 
    def unite(self,x,y):
        self.link(self.find(x),self.find(y))
 
    def size(self):
        S=set()
        for a in range(self.n):
            S.add(self.find(a))
        return len(S)
def is_power(a,b):#aはbの累乗数か
    now=b
    while now<a:
        now*=b
    if now==a:return True
    else:return False
def bin_(num,size):
    A=[0]*size
    for a in range(size):
        if (num>>(size-a-1))&1==1:
            A[a]=1
        else:
            A[a]=0
    return A
def get_facs(n,mod_=0):
    A=[1]*(n+1)
    for a in range(2,len(A)):
        A[a]=A[a-1]*a
        if(mod>0):A[a]%=mod_
    return A
def comb(n,r,mod,fac):
    if(n-r<0):return 0
    return (fac[n]*pow(fac[n-r],mod-2,mod)*pow(fac[r],mod-2,mod))%mod
def next_comb(num,size):
    x=num&(-num)
    y=num+x
    z=num&(~y)
    z//=x
    z=z>>1
    num=(y|z)
    if(num>=(1<<size)):return False
    else:
        return num
def get_primes(n,type="int"):
    A=[True]*(n+1)
    A[0]=False
    A[1]=False
    for a in range(2,n+1):
        if A[a]:
            for b in range(a*2,n+1,a):
                A[b]=False
    if(type=="bool"):return A
    B=[]
    for a in range(n+1):
        if(A[a]):B.append(a)
    return B
def is_prime(num):
    if(num<=2):return False
    i=2
    while i*i<=num:
       if(num%i==0):return False
       i+=1
    return True
def ifelse(a,b,c):
    if a:return b
    else:return  c
def join(A,c=" "):
    n=len(A)
    A=list(map(str,A))
    s=""
    for a in range(n):
        s+=A[a]
        if(a<n-1):s+=c
    return s
def factorize(n,type_="dict"):
    b = 2
    list_ = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            list_.append(b)
        b+=1
    if n > 1:list_.append(n)
    if type_=="dict":
        dic={}
        for a in list_:
            if a in dic:
                dic[a]+=1
            else:
                dic[a]=1
        return dic
    elif type_=="list":
        return list_
    else:
        return None
def floor_(n,x=1):
    return x*(n//x)
def ceil_(n,x=1):
    return x*((n+x-1)//x)
###################################################
def main():
    a,b,M=map(int,input().split())
    A=list(map(int,input().split()))
    B=list(map(int,input().split()))
    ans=min(A)+min(B)
    for _ in range(M):
        x,y,c=map(int,input().split())
        x-=1
        y-=1
        ans=min(ans,A[x]+B[y]-c)
    print(ans)


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()))
checkout = min(a)+min(b)

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

print(checkout)

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

while True:
  try:
    tmp1,tmp2,tmp3 = map(int,input().split())
    x.append(tmp1)
    y.append(tmp2)
    c.append(tmp3)
  except:
    break
    
not_use = min(a) + min(b)

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

Submission status: Accepted

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

li = []
for z in Z:
    li.append(a[z[0]-1]+b[z[1]-1]-z[2])
li.append(min(a)+min(b))
print(min(li))

Submission status: Accepted

Solution code:
a, b, m=map(int, input().split())
a=list(map(int, input().split()))
b=list(map(int, input().split()))
mprice=min(a)+min(b)
for _ in range(m):
  x, y, c=map(int, input().split())
  p=a[x-1]+b[y-1]-c
  if p<mprice:
    mprice=p
print(mprice)

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

Min_1 = min(A_list) + min(B_list)
Min_2 = []
for m in M_list:
  Min_2.append(A_list[m[0] - 1] + B_list[m[1] - 1] - m[2])
if Min_1 < min(Min_2):
  print(Min_1)
else:
  print(min(Min_2))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin
A, B, M = [int(_) for _ in stdin.readline().rstrip().split()]
A = [int(_) for _ in stdin.readline().rstrip().split()]
B = [int(_) for _ in stdin.readline().rstrip().split()]
XYC = [list(map(int, stdin.readline().rstrip().split())) for _ in range(M)]
ans = [min(A)+min(B)]
for x, y, c in XYC:
  ans.append(A[x-1]+B[y-1]-c)
print(min(ans))

Submission status: Accepted

Solution code:
import numpy as np
tmp = list(map(int, input().split(' ')))
A = tmp[0]
B = tmp[1]
m = tmp[2]
a = list(map(int, input().split(' ')))
b = list(map(int, input().split(' ')))
xyc = [ list(map(int,input().split(" "))) for i in range(m)]
ans = min(a)+min(b)
for i in range(m):
    ans = min(a[xyc[i][0]-1]+b[xyc[i][1]-1]-xyc[i][2],ans)
print(ans)

Submission status: Accepted

Solution code:
a,b,m = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = [tuple(map(int,input().split())) for i in range(m)]
p = [min(a)+min(b)]
for t in c:
    p.append(a[t[0]-1]+b[t[1]-1]-t[2])
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 = [tuple(map(int,input().split())) for i in range(m)]
p = min(a)+min(b)
for t in c:
    p = min(p,a[t[0]-1]+b[t[1]-1]-t[2])
print(p)

Submission status: Accepted

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

P = list(map(int, input().split()))
Q = list(map(int, input().split()))

res = min(P) + min(Q)

for _ in range(M):
    x, y, c = map(int, input().split())
    x -= 1
    y -= 1

    res = min(res, P[x] + Q[y] - c)

print(res)

Submission status: Accepted

Solution code:
# from math import factorial,sqrt,ceil,gcd
# from itertools import permutations as permus
# from collections import deque,Counter
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix

# strlist = "abcdefghijklmnopqrstuvwxyz"
A,B,M = map(int,input().split())
arrA = list(map(int,input().split()))
arrB = list(map(int,input().split()))
times = M
table = []
for _ in range(times):
    x,y,c = list(map(int,input().split())) # 行列の場合
    table.append(arrA[x-1]+arrB[y-1]-c)

simplelow = min(arrA)+min(arrB)
ans = min(simplelow,min(table))

print(ans)
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

m = min(a) + min(b)
for ticket in xyc:
    x, y, c = ticket
    temp = a[x - 1] + b[y - 1] - c
    m = min(temp, m)
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()))

minv = min(a) + min(b)

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

    tmp = a[x-1] + b[y-1] - c

    if tmp < minv:
        minv = tmp

print(minv)

Submission status: Accepted

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

ans=min(a)+min(b)

for k in range(M):
    i=t[k][0]
    j=t[k][1]
    
    Y=a[i-1]+b[j-1]-t[k][2]
    if Y<=ans:
        ans=Y

print(ans)

Submission status: Accepted

Solution code:
#ABC150-A
if False:
    K,X=map(int,input().split())
    print('Yes' if 500*K>=X else 'No')

#ABC150-B
if False:
    N=int(input())
    S=input()
    print(S.count('ABC'))

#ABC150-C
if False:
    import itertools
    N=int(input())
    dic=list(itertools.permutations(list(range(1,N+1))))
    # print(dic)
    P=tuple(int(i) for i in input().split())
    Q=tuple(int(i) for i in input().split())

    print(abs(dic.index(P)-dic.index(Q)))

#HPC2020-B
if True:
    A,B,M=map(int,input().split())
    a=[int(i) for i in input().split()]
    b=[int(i) for i in input().split()]
    M=[tuple(int(j) for j in input().split()) for i in range(M)]
    ans=min(a)+min(b)
    for x,y,c in M:
        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, y, c = [], [], []
for _ in range(M):
    xi, yi, ci = map(int, input().split())
    x.append(xi)
    y.append(yi)
    c.append(ci)

# print(A, B, M)
# print(a)
# print(b)
# print(x)
# print(y)
# print(c)

# M個全部試す or min同士
cost1 = min(a) + min(b)
cost = [cost1]

for j in range(M):
    xj, yj, cj = x[j], y[j], c[j]
    costj = a[xj - 1] + b[yj - 1] - cj
    cost.append(costj)

print(min(cost))

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():

    A,B,M=map(int,input().split())
    A=list(map(int,input().split()))
    B=list(map(int,input().split()))
    L=[list(map(int,input().split())) for i in range(M)]

    ans=min(A)+min(B)

    for l in L:
        ans=min(ans,A[l[0]-1]+B[l[1]-1]-l[2])
    print(ans)


resolve()

Submission status: Accepted

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

result = min(a)+min(b)

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

print(result)

Submission status: Accepted

Solution code:
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
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:
def myAnswer(a:list,b:list,XYC:list) -> int:
   ans = min(a) + min(b)
   for x,y,c in XYC:
      total = a[x-1] + b[y-1] - c
      ans = min(total,ans)
   return ans



def modelAnswer():
   tmp=1
def main():
   A, B, M = map(int,input().split())
   a = list(map(int,input().split()))
   b = list(map(int,input().split()))
   XYC = []
   for _ in range(M):
      XYC.append(list(map(int,input().split())))
   print(myAnswer(a,b,XYC))

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

price=[0]*(M+1)

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

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

print(min(price))