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=[int(x) for x in input().rstrip().split()]
a=[int(x) for x in input().rstrip().split()]
b=[int(x) for x in input().rstrip().split()]

ans=float('inf')
for i in range(M):
  x,y,c=[int(x) for x in input().rstrip().split()]
  ans=min(ans,a[x-1]+b[y-1]-c)
mm=min(a)+min(b)
print(min(ans,mm))

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

Submission status: Accepted

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

A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
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 = list(map(int, input().split()))
b_list = list(map(int, input().split()))
m_list = [list(map(int, input().split())) for i in range(m)]

ans = min(a_list) + min(b_list)

for i in range(m):
    ans = min(ans, a_list[m_list[i][0] - 1] + b_list[m_list[i][1] - 1] - m_list[i][2])

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
A, B, M = map(int, input().split())
PA = [int(x) for x in input().split()]
PB = [int(x) for x in input().split()]
XYC = [tuple(map(int, input().split())) for _ in range(M)]

p1 = min(PA) + min(PB)
p2 = 10 ** 10
for x, y, c in XYC:
    p2 = min(PA[x - 1] + PB[y - 1] - c, p2)

print(min(p1, p2))

Submission status: Accepted

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

a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
XYC = [[int(x) for x in 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())
aa=list(map(int,input().split()))
bb=list(map(int,input().split()))
XC=[]
for i in range(M):
  XC.append(list(map(int,input().split())))
ans=min(aa)+min(bb)
for i in range(M):
  ans=min(ans,aa[XC[i][0]-1]+bb[XC[i][1]-1]-XC[i][2])
print(ans)

Submission status: Accepted

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

ans = min(a)+min(b)

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

print(ans)

Submission status: Accepted

Solution code:
from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations # (string,3) 3回
from collections import deque
from collections import defaultdict
import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
a,b,m = readInts()
A = readInts()
B = readInts()
res = min(A) + min(B)
for i in range(m):
    x,y,c = readInts()
    x -=1;y-=1;
    res = min(res,A[x] + B[y] - 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()))
xyc = []
for _ in range(m):
    xyc.append(list(map(int, input().split())))
ans = min(a) + min(b)

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

Submission status: Accepted

Solution code:
a, b, m = map(int, input().split())
li_a = list(map(int, input().split()))
li_b = list(map(int, input().split()))
li_c = []
for _ in range(m):
  x, y, c = map(int, input().split())
  x, y = x-1, y-1
  li_c.append(li_a[x]+li_b[y]-c)
li_a.sort()
li_b.sort()
li_c.sort()
ans = min(li_a[0]+li_b[0], li_c[0])
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a,b,m=map(int,input().split())
alist=list(map(int,input().split()))
blist=list(map(int,input().split()))
minimum=100000000000000
for i in range(m):
  x,y,z=map(int,input().split())
  minimum=min(minimum,alist[x-1]+blist[y-1]-z)
alist.sort()
blist.sort()
minimum=min(minimum,alist[0]+blist[0])
print(minimum)

Submission status: Accepted

Solution code:
A, B, M = map(int, input().split())
an = list(map(int, input().split()))
bn = list(map(int, input().split()))
ans = min(an)+min(bn)
for i in range(M):
    x, y, c = map(int, input().split())
    ans = min(ans, an[x-1] + bn[y-1] - c)
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()))
xyc = [list(map(int,input().split())) for _ in range(m)]
a_min = min(a_list)
b_min = min(b_list)
s = a_min + b_min
for i in range(m):
    x,y,c = xyc[i][0]-1,xyc[i][1]-1,xyc[i][2]
    s = min(s, a_list[x]+b_list[y]-c)
print(s)

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 s in range(m)]
ans = []
for m in mlist:
	tmp = alist[m[0]-1] + blist[m[1]-1] -m[2]
	ans.append(tmp)
x = min(alist) + min(blist)
ans.append(x)
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()))

oldp = min(a)+min(b)

for _ in range(M):
    x, y, cp = map(int,input().split())
    p = a[x-1]+b[y-1]-cp
    if oldp > p:
        oldp = p

print(oldp)

Submission status: Accepted

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

ans = 1000000
for i in range(m):
    x, y, c = map(int, input().split())
    ans = min(ans, A[x - 1] + B[y - 1] - c)
A.sort()
B.sort()
ans = min(ans, A[0] + B[0])
print(ans)

Submission status: Accepted

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

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

# 割引券を使用しない
result = min(a) + min(b)

# 割引券を使用する
for i 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:

def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def s4(n):return [[x for x in s] for s in s2(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes if b else no)
# from sys import setrecursionlimit
# setrecursionlimit(1000000)
# from collections import Counter,deque,defaultdict
# import itertools
# import math
# import networkx as nx
# from bisect import bisect_left,bisect_right
# from heapq import heapify,heappush,heappop
a,b,m=n1()
A=n1()
B=n1()
X=n3(m)

A2=sorted(A)
B2=sorted(B)
ans=A2[0]+B2[0]
for a,b,c in X:
    if A[a-1]+B[b-1]-c<ans:
        ans=A[a-1]+B[b-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()))

#c = [input().split() for l in range(M)]

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 = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
x = []
y = []
c = []
for i in range(m):
	xs,ys,cs = map(int,input().split())
	x.append(xs)
	y.append(ys)
	c.append(cs)

ans1 = 10**10
for j in range(m):
	if ans1 >= a[x[j]-1] + b[y[j]-1] - c[j]:
		ans1 = a[x[j]-1] + b[y[j]-1] - c[j]
ans2 = min(a)+min(b)
print(min(ans1,ans2))

Submission status: Accepted

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

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

ans = min_A + min_B
for i in range(M):
    x, y, c = map(int, input().split())
    ans = min(price_A[x-1]+price_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()))

ans=min(a)+min(b)
temp=0

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

print(ans)

Submission status: Accepted

Solution code:
A, B, M = map(int, input().split())
As = list(map(int, input().split()))
Bs = list(map(int, input().split()))
Ds = []
for i in range(M):
  x, y, c = map(int, input().split())
  x, y = x-1, y-1
  D = As[x]+Bs[y]-c
  Ds.append(D)
r = min(min(As)+min(Bs), min(Ds))
print(r)

Submission status: Accepted

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()

from collections import defaultdict, deque, Counter
from sys import exit
import heapq
import math
import fractions
import copy
from itertools import permutations
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

A, B, M = getNM()
# それぞれ冷蔵庫の値段
ref_a = getList()
ref_b = getList()
# 一枚だけ使える
ticket = [getList() for i in range(M)]

ans = min(ref_a) + min(ref_b)
for i in ticket:
    opt = ref_a[i[0] - 1] + ref_b[i[1] - 1] - i[2]
    ans = min(ans, opt)
print(ans)

Submission status: Accepted

Solution code:
A,B,M = map(int,input().split())
Ai = list(map(int,input().split()))
Bi = list(map(int,input().split()))
amin = min(Ai)
bmin= min(Bi)
min = amin+bmin
for i in range(M):
	xi,yi,ci = map(int,input().split())
	if Ai[xi-1] + Bi[yi-1] - ci < min:
		min = Ai[xi-1] + Bi[yi-1] - ci
print(min)

Submission status: Accepted

Solution code:
# hitachi2020_b.py
_, _, M = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
X = []
Y = []
C = []
amin = min(A)
bmin = min(B)
for i in range(M):
    x, y, c = map(int, input().split())
    X.append(x)
    Y.append(y)
    C.append(c)

ans = amin+bmin
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())
al = list(map(int, input().split()))
bl = list(map(int, input().split()))
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()))
ans = min(a) + min(b)
for _ in range(m):
    x, y, c= map(int, input().split())
    ans = min(a[x - 1] + b[y - 1] - c, ans)
print(ans)

Submission status: Accepted

Solution code:
a,b,m = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
xyc = [list(map(int,input().split())) for nesya in range(m)]
cheap = min(a)+min(b)
for hoge in xyc:
  ch = a[hoge[0]-1]+b[hoge[1]-1]-hoge[2]
  cheap = min(ch,cheap)
print(cheap)

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

inf = float("inf")
posibility = inf

for m in range(M):
    x,y,c=map(int,input().split())
    tmp_posibility=A_li[x-1]+B_li[y-1]-c
    posibility=min(posibility,tmp_posibility)
 

no_c = min(A_li)+min(B_li)
decition = min(posibility,no_c)

print(decition)

Submission status: Accepted

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

# とりあえず最小
minc=min(a)+min(b)

for v in c:
  minc = min(minc, (a[v[0]-1]+b[v[1]-1]-v[2]))

print(minc)

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:
#!/usr/bin/env python3


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

    min_cost = 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 min_cost > cost:
            min_cost = cost

    print(min_cost)


if __name__ == "__main__":
    main()

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

Submission status: Accepted

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

#入力
# s = list(input()[0:-1])
# n = int(input())
A,B,M = map(int, input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
# w = [int(input()) for i in range(n)]

xyc=[]
for i in range(M):
    x,y,c = map(int, input().split())
    xyc.append((x,y,c))
     
def main():
    mn = sorted(a)[0]+sorted(b)[0]
    for x, y, c in xyc:
        mn = min(mn, a[x-1]+b[y-1] - c)

    print(mn)
        
if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
A,B,M=map(int, input().split())
AList=list(map(int, input().split()))
BList=list(map(int, input().split()))
XYCList = [list(map(int, input().split())) for i in range(M)]
ANS=[min(AList)+min(BList)]
i=0
while i<M:
    ANS.append(AList[XYCList[i][0]-1]+BList[XYCList[i][1]-1]-XYCList[i][2])
    i+=1
print(min(ANS))

Submission status: Accepted

Solution code:
#!/usr/bin/python
# -*- coding: utf-8 -*-

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

a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
xyc = []
for _ in range(0,M):
    xyc.append([int(x) for x in input().split()])

ans = 0

ans = min(a) + min(b)

coupon = []

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

ans = min(ans,min(coupon))

print(ans)

Submission status: Accepted

Solution code:
import bisect,collections,copy,heapq,itertools,math,numpy,string
import sys
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def SS(): return map(str,sys.stdin.readline().rstrip().split())
def II(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())

A,B,M = II()
a = LI()
b = LI()
ticket = [LI() for _ in range(M)]

cost = min(a) + min(b)
costl = [a[t[0]-1] + b[t[1]-1] - t[2] for t in ticket]

print(min(cost,min(costl)))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a, b, m = map(int, input().split())
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
min_cost = min(a_list) + min(b_list)

for _ in range(m):
    x, y, c = map(int, input().split())
    _a = a_list[x-1]
    _b = b_list[y-1]
    cost = _a + _b - c
    min_cost = min(cost, min_cost)
print(min_cost)

Submission status: Accepted

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

discount = []

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

ans_a = float('inf')
ans_b = float('inf')

for e in a:
    ans_a = min(ans_a, e)

for e in b:
    ans_b = min(ans_b, e)

ans = ans_a + ans_b

for x,y,c in discount:
    temp = a[x]+b[y]-c
    ans = min(ans, temp)

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 i in range(m):
	xx, yy, cc = map(int, input().split())
	x.append(xx)
	y.append(yy)
	c.append(cc)


ans = min(a) + min(b)

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

mn = min(a) + min(b)

for i in range(M):
    t = a[X[i]-1] + b[Y[i]-1] - C[i]
    mn = min(t, mn)

print(mn)

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 = list(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)]
MIN = min(A)+min(B)
for xyc in XYC:
    MIN = min(MIN,A[xyc[0]-1]+B[xyc[1]-1]-xyc[2])
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()))
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:
def resolve():
    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()]
    zyc = [list(map(int, input().split())) for _ in range(M)]

    minAB = min(a) + min(b)
    for z, y, c in zyc:
        tmp = a[z - 1] + b[y - 1] - c
        minAB = min(minAB, tmp)
    print(minAB)


resolve()

Submission status: Accepted

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

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

for x, y, c in xyc:
    rets += [a[x-1] + b[y-1] - c]
print(min(rets))

Submission status: Accepted

Solution code:
A,B,m = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
li2=[input() for i in range(m)]
c = []
for i in range(m):
    c.append( [int(x.strip()) for x in li2[i].split()])

ans = min(a) + min (b)

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

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=[list(map(int,input().split())) for i in range(M)]
d = 0
e = 0
aa=sorted(a)
bb=sorted(b)

e=aa[0]+bb[0]

for i in range(M):
	d=a[c[i][0]-1]+b[c[i][1]-1]-c[i][2]
	if d<e:
		e=d

print(e)

Submission status: Accepted

Solution code:
A, B, m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
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):
    ans = min(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())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

ans = []
ans.append(min(A)+min(B))


for i in range(m):
    M = list(map(int,input().split()))
    tmp = A[M[0]-1] + B[M[1]-1] -M[2]
    ans.append(tmp)

print(min(ans))

Submission status: Accepted

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


def read():
    _, _, M = map(int, input().strip().split())
    A = list(map(int, input().strip().split()))
    B = list(map(int, input().strip().split()))
    XYC = []
    for i in range(M):
        x, y, c = map(int, input().strip().split())
        XYC.append((x, y, c))
    return A, B, M, XYC


def solve(A, B, M, XYC):
    min_cost = min(A) + min(B)
    for x, y, c in XYC:
        cost = A[x-1] + B[y-1] - c
        min_cost = min(min_cost, cost)
    return min_cost


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))

Submission status: Accepted

Solution code:
import sys

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

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

print(min(t, sorted(a)[0] + sorted(b)[0]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
A, B, M = map(int, input().split())
As = list(map(int, input().split()))
Bs = list(map(int, input().split()))
coupons = []
for _ in range(M):
    x, y, c = map(int, input().split())
    coupons.append((x, y, c))

price_min = min(As) + min(Bs)
coupon_min = min([As[x - 1] + Bs[y - 1] - c for (x, y, c) in coupons])

print(min((price_min, coupon_min)))

Submission status: Accepted

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

for _ in range(m):
    x, y, c = map(int, input().split())
    x -= 1
    y -= 1
    total = a_list[x] +b_list[y] - c
    money.append(total)
money.append(min(a_list) + min(b_list))
print(min(money))

Submission status: Accepted

Solution code:
# For taking integer inputs.
def inp():
    return(int(input()))


# For taking List inputs.
def inlist():
    return(list(map(int, input().split())))


# For taking string inputs. Actually it returns a List of Characters, instead of a string, which is easier to use in Python, because in Python, Strings are Immutable.
def instr():
    s = input()
    return(list(s[:len(s)]))


# For taking space seperated integer variable inputs.
def invr():
    return(map(int, input().split()))


A, B, M = invr()

a = inlist()  # all fridger cost list
b = inlist()  # all oven cost list

C = []
for i in range(M):
    C.append(inlist())

costs_of_using_tickets = [0] * M

for i in range(M):
    ci = C[i]
    costs_of_using_tickets[i] = a[ci[0]-1] + b[ci[1]-1] - ci[2]

cost_of_not_using_tickets = min(a) + min(b)

print(min(cost_of_not_using_tickets, min(costs_of_using_tickets)))

Submission status: Accepted

Solution code:
from sys import stdin
import math
import re
import queue

input = stdin.readline

MOD = 1000000007
INF = 122337203685477580

def solve():
    A,B,M = map(int, input().split())
    v1 =list(map(int, input().split())) 
    v2 =list(map(int, input().split())) 
    res = INF
    for i in range(M):
        X,Y,C = map(int, input().split())
        res = min(res,v1[X-1] + v2[Y-1] - C)

    res = min(res,min(v1) + min(v2))
    res = max(0,res)
    print(res)


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
import math
from collections import deque
from collections import defaultdict

#自作関数群
def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()
def factorization(n):
	res = []
	if n%2==0:
		res.append(2)
	for i in range(3,math.floor(n//2)+1,2):
		if n%i==0:
			c = 0
			for j in res:
				if i%j==0:
					c=1
			if c==0:
				res.append(i)
	return res
def fact2(n):
	p = factorization(n)
	res = []
	for i in p:
		c=0
		z=n
		while 1:
			if z%i==0:
				c+=1
				z/=i
			else:
				break
		res.append([i,c])
	return res
def fact(n):#階乗
	ans = 1
	m=n
	for _i in range(n-1):
		ans*=m
		m-=1
	return ans
def comb(n,r):#コンビネーション
	if n<r:
		return 0
	l = min(r,n-r)
	m=n
	u=1
	for _i in range(l):
		u*=m
		m-=1
	return u//fact(l)
def combmod(n,r,mod):
	return (fact(n)/fact(n-r)*pow(fact(r),mod-2,mod))%mod
def printQueue(q):
	r=copyQueue(q)
	ans=[0]*r.qsize()
	for i in range(r.qsize()-1,-1,-1):
		ans[i] = r.get()
	print(ans)
class UnionFind():
	def __init__(self, n):
		self.n = n
		self.parents = [-1]*n

	def find(self, x): # root
		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 -1*self.parents[self.find(x)]

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

	def members(self,x): # much time
		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()} # 1~n
def bitArr(n):#ビット全探索
	x = 1
	zero = "0"*n
	ans = []
	ans.append([0]*n)
	for i in range(2**n-1):
		ans.append(list(map(lambda x:int(x),list((zero+bin(x)[2:])[-1*n:]))))
		x+=1
	return ans;
def arrsSum(a1,a2):
	for i in range(len(a1)):
		a1[i]+=a2[i]
	return a1
def maxValue(a,b,v):
	v2 = v
	for i in range(v2,-1,-1):
		for j in range(v2//a+1): #j:aの個数
			k = i-a*j
			if k%b==0:
				return i
	return -1
def copyQueue(q):
	nq = queue.Queue()
	n = q.qsize()
	for i in range(n):
		x = q.get()
		q.put(x)
		nq.put(x)
	return nq

a,b,m = readInts()
a_arr = readInts()
b_arr = readInts()
xyc = [[] for i in range(a)]
for i in range(m):
	x,y,c = readInts()
	xyc[x-1].append([y-1,c])

ans = min(a_arr)+min(b_arr)

for i in range(len(xyc)):
	for j in xyc[i]:
		ans = min(ans,a_arr[i]+b_arr[j[0]]-j[1])

print(ans)

Submission status: Accepted

Solution code:
a,b,m = map(int, input().split())
al = list(map(int, input().split()))
bl = list(map(int, input().split()))
xyc = [list(map(int, input().split())) for i in range(m)]
ans = min(al)+min(bl)
for l in xyc:
    p = al[l[0]-1] + bl[l[1]-1] -l[2]
    ans = min(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()))
asorted = sorted(a)
bsorted = sorted(b)
cost = {asorted[0]+bsorted[0]}

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