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(i) for i in input().split()]
al = [int(i) for i in input().split()]
bl = [int(i) for i in input().split()]
xyc = [[int(i) for i in input().split()] for _ in range(M)]

print(min(min(al)+min(bl), min([al[m[0]-1] + bl[m[1]-1] - m[2] for m in xyc])))

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

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
A, B, M = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
min_A = min(A)
min_B = min(B)

C = []
d = []

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

print(min(min(C), min_A+min_B))

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict as dd
input = sys.stdin.readline
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
mn = min(b)
d = dd(list)
for _ in range(M):
  x, y, c = map(int, input().split())
  d[x - 1].append((y - 1, c))
res = float("inf")
for i in range(A):
  x = a[i]
  tt = mn + 0
  for t in d[i]:
    y, c = t
    tt = min(tt, b[y] - c)
  res = min(res, x + tt)
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()))

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

mn = min(mn, min(A) + min(B))

print(mn)

Submission status: Accepted

Solution code:
a,b,m=map(int,input().split())
la=list(map(int,input().split()))
lb=list(map(int,input().split()))
l=[list(map(int,input().split())) for i in range(m)]

ll=[] 
for i in range(m):
    ll.append(la[l[i][0]-1]+lb[l[i][1]-1]-l[i][2])

ll.append(min(la)+min(lb))
print(min(ll))

Submission status: Accepted

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

ans=min(a_l)+min(b_l)

for i in range(m):
    ans=min(ans, a_l[xyc[i][0]-1]+b_l[xyc[i][1]-1]-xyc[i][2])

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

ans = min(AList) + min(BList)
arr = []
arr.append(ans)

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

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 i in range(M)]

noti=min(a)+min(b)
ans=noti
c=0

for i in range(M):
    c=a[xyc[i][0]-1] + b[xyc[i][1]-1] -xyc[i][2]
    ans=min(ans,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)]

ans=[]
for x,y,c in XYC:
  x,y=x-1,y-1
  ans.append(A[x]+B[y]-c)
A.sort()
B.sort()
ans.append(A[0]+B[0])
ans.sort()
print(ans[0])

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
A, B, M = map(int, input().split())
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
ans = min(a_list) + min(b_list)
for i in range(M):
    x, y, c = map(int, input().split())
    ans = min(ans, a_list[x - 1] + b_list[y - 1] - c)

print(ans)

Submission status: Accepted

Solution code:
a,b,m = map(int,input().split())
als = list(map(int,input().split()))
bls = list(map(int,input().split()))
xls = [list(map(int,input().split())) for i in range(m)]
ans = min(als)+min(bls)

for i in xls:
    # print(i)
    ans = min(ans,als[i[0]-1]+bls[i[1]-1]-i[2])
# print(als,bls,xls)
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()))

minVal = min(a) + min(b)

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

print(minVal)

Submission status: Accepted

Solution code:
import sys


def read():
    return sys.stdin.readline().rstrip()


def main():
    _, _, m = map(int, read().split())
    a = [int(i) for i in read().split()]
    b = [int(i) for i in read().split()]
    ans = min(a) + min(b)
    for i in range(m):
        x, y, c = map(int, read().split())
        ans = min(a[x - 1] + b[y - 1] - c, ans)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#import sys
MOD = 10 ** 9 + 7
INFI = 10**10
#input = sys.stdin.readline
import math

import itertools

#import bisect

import copy
from functools import lru_cache

def sosuhante(n):
    for k in range(2, int(math.sqrt(n))+1):
        if n% k ==0:
            return False
    return True
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def kingaku(a,b,n):
    keta=len(str(n))
    return a*n+b*keta

def my_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default

#    h,w,a,b = map(int, input().split())
#    c = [[0 for j in range(n)] for i in range(n)]



def main():
    A,B,M=map(int,input().split())
    a=list(map(int,input().split()))
    b=list(map(int,input().split()))
    wari=[]
    for i in range(M):
        x,y,c=map(int,input().split())
        wari.append([x,y,c])
    ans=min(a)+min(b)
    for i in range(M):
        temp=a[wari[i][0]-1]+b[wari[i][1]-1]-wari[i][2]
        ans=min(ans,temp)
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:

#####

import numpy as np
from numpy import newaxis, float32, float64, int32, int64, int16, int8, uint8, uint32, complex64, complex128

#####

def getIntList(inp):
	return [int(_) for _ in inp]


from sys import stdin
import sys

def getInputs():
	inputs=[]
	for line in stdin:
		line=line.split()
		inputs.append(line)
	return inputs


def func(a,b,m,
	aValues,
	bValues,
	xs,
	ys,
	cs):
	
	aValues=np.array(aValues)
	bValues=np.array(bValues)
	
	mi=aValues.min()+bValues.min()
	for x,y,c in zip(xs,ys,cs):
		v=aValues[x]+bValues[y]-c
		if v<mi: mi=v
		
	print(mi)
	



def main(inputs):
	a,b,m=getIntList(inputs[0])
	aValues=getIntList(inputs[1])
	bValues=getIntList(inputs[2])
	xs=np.empty(m, int32)
	ys=np.empty(m, int32)
	cs=np.empty(m, int32)
	for i in range(m):
		xs[i],ys[i],cs[i]=getIntList(inputs[3+i])
	xs-=1
	ys-=1
	
# 	print(a,b,m)
# 	print(aValues)
# 	print(bValues)
# 	print(xs)
# 	print(ys)
# 	print(cs)

	func(a, b, m, aValues, bValues, xs, ys, cs)
	

if __name__=="__main__":
	inputs=getInputs()
# 	inputs=simInputs()
	main(inputs)

Submission status: Accepted

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

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

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()))
coupon = [list(map(int, input().split())) for i in range(m)]
cm = (10**5) * 2


for i in range(m):
  cm = min(a[coupon[i][0]-1] + b[coupon[i][1]-1] - coupon[i][2], cm)

a.sort()
b.sort()

print(min(a[0]+b[0],cm))

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, list(input().split()))) for i in range(m)]

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

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

res = min(alist) + min(blist)

for x, y, c in xyclist:
    cand = alist[x-1] + blist[y-1] - c
    if cand < res:
        res = cand

print(res)

Submission status: Accepted

Solution code:
A, B, N = map(int, input().split())
La =list(map(int, input().split())) 
Lb =list(map(int, input().split()))
ans = min(La)+min(Lb)
for i in range (N):
  W = list(map(int, input().split())) 
  x = W[0]-1
  y = W[1]-1
  c = W[2]
  price = La[x] + Lb[y] -c
  if price < ans:
    ans = price
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()))
d=[list(map(int,input().split())) for _ in range(m)]
ans=min(A)+min(B)
for i in range(m):
    r=d[i][0]-1
    l=d[i][1]-1
    val=d[i][2]
    ans=min(ans,(A[r]+B[l]-val))



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()))
min_tikets = 10000000
for i in range(m):
    x,y,c = list(map(int,input().split()))
    if a[x-1]+b[y-1]-c < min_tikets:
        min_tikets =a[x-1]+b[y-1]-c
a_sort=sorted(a)
b_sorted = sorted(b)
if a_sort[0]+b_sorted[0] < min_tikets:
    print(a_sort[0]+b_sorted[0])
else:
    print(min_tikets)

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

ans=10**10

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

    ans=min(ans,alst[x-1]+blst[y-1]-c)

ans=min(ans,min(alst)+min(blst))

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

ans = min(a) + min(b)

for x, y, c in d:
    ans = min(ans, a[x]+b[y]-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 = []

cand = []
for i in range(M):
    lx, ly, lc = map(int, input().split())
    x.append(lx)
    y.append(ly)
    c.append(lc)

cand.append(min(a)+min(b))
for i in range(M):
    cand.append(a[x[i]-1] + b[y[i]-1] - c[i])

ans = min(cand)
print(ans)

Submission status: Accepted

Solution code:
A, B, M = map(int, input().split())
*a, = map(int, input().split())
*b, = map(int, input().split())
ab = min(a) + min(b)
for i in range(M):
    x, y, c = map(int, input().split())
    ab = min(ab, a[x - 1] + b[y - 1] - c)
print(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()))

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:
import sys
import bisect
MAX_INT = int(10e15)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

A,B,M = IL()
a = IL()
b = IL()
xyc = [IL() 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)

"""
3 2 1
3 5 4
3 5
2 2 2
"""

Submission status: Accepted

Solution code:
#!python3.4.3

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(' '))
  tmp = a[x-1] + b[y-1] - c
  
  min_ = min(tmp, min_)
  
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 = 10**9
for i in range(M):
  x,y,c = map(int,input().split())
  s = a[x-1] + b[y-1] - c
  ans = min(ans,s)

ma = 10**9
mb = 10**9
for j in range(A):
  ma = min(ma,a[j])
for k in range(B):
  mb = min(mb,b[k])
ans = min(ans,ma+mb)
print(ans)

Submission status: Accepted

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

ans = min(frid) + min(mic)

for _ in range(m):
    x, y, c = map(int, input().split())
    disc = frid[x-1] + mic[y-1] - c

    if disc < ans:
        ans = disc
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 -= 1
  y -= 1
  X.append(x)
  Y.append(y)
  C.append(c)
  
Waribiki = []
Waribiki.append(min(A) + min(B))
for i in range(m):
  Waribiki.append(A[X[i]] + B[Y[i]] - C[i])
print(min(Waribiki))

Submission status: Accepted

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

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

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

ans = min(ans, min(a)+min(b))
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):
    i,j,c=map(int,input().split())
    ans=min(ans, A[i-1]+B[j-1]-c)
print(ans)

Submission status: Accepted

Solution code:
def main():
    A,B,M=map(int, input().split())
    a=list(map(int, input().split()))
    b=list(map(int, input().split()))
    
    min_a = min(a)
    min_b = min(b)
    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)
    return

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a,b,m = map(int, input().split())
a_lis = list(map(int, input().split()))
b_lis = list(map(int, input().split()))
ans_lis = [min(a_lis)+min(b_lis)]
for _ in range(m):
    x,y,z = map(int, input().split())
    tmp = a_lis[x-1]+b_lis[y-1]-z
    ans_lis.append(tmp)
print(min(ans_lis))

Submission status: Accepted

Solution code:
from collections import defaultdict
from collections import deque
from string import ascii_uppercase
import sys, bisect, math, heapq

stdin = sys.stdin
read_int = lambda : list(map(int,stdin.readline().split()))
read_str = lambda : stdin.readline().rstrip()

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

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

if __name__ == "__main__":
    print(solve())

Submission status: Accepted

Solution code:
n,m,c=map(int,input().split())

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

a_min=min(a)
b_min=min(b)

tmp=a_min+b_min

for i in range(c):
  i,j,k=map(int,input().split())
  i-=1
  j-=1
  tmp=min(tmp,a[i]+b[j]-k)
print(tmp)

Submission status: Accepted

Solution code:
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
newa = sorted(a)
newb = sorted(b)
ans = newa[0] + newb[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()))

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

z=[0]*M

p=min(a)+min(b)

for i in range(M):
    z[i]=a[d[i][0]-1]+b[d[i][1]-1]-d[i][2]

q=min(z)


print(min(p,q))

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

ans = 3*(10**5)

for _ in range(m):
  x,y,c = map(int,input().split())
  x-=1; y-=1
  ans = min(ans,aaa[x]+bbb[y]-c)

aaa = sorted(aaa)
bbb = sorted(bbb)

ans = min(ans,aaa[0]+bbb[0])
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict, Counter, deque

NA, NB, NM = list(map(int, input().split()))

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


best = min(A) + min(B)

for i in range(NM):
    x, y, c = list(map(int, input().split()))
    best = min(best, A[x - 1] + B[y - 1] - c)


print(best)

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

o = min(a_list) + min(b_list)
for _ in range(M):
    x, y, c = map(int, input().split())
    t_a = a_list[x-1]
    t_b = b_list[y-1]
    r = t_a + t_b - c
    if o is None or o > r:
        o = r


print(o)

Submission status: Accepted

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

a_list = [int(e) for e in input().split()]
b_list = [int(e) for e in input().split()]

min_price = min(a_list)+min(b_list)

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

Submission status: Accepted

Solution code:
import numpy as np
import collections

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


answer=0
x=[]
y=[]
c=[]

answer = min(a)+min(b)

for i in range(M):
    x1,y1,c1 = map(int,input().split())
    if a[x1-1]+b[y1-1]-c1 < answer:
        answer = a[x1-1]+b[y1-1]-c1

#for x in c.values():
#    answer +=x*(x-1) // 2

print(answer)

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 = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
discount = 10000000000
for i in range(M):
    C = [int(i) for i in input().split()]
    num = a[C[0]-1] + b[C[1]-1] -C[2]
    if discount > num:
        discount = num
a.sort()
b.sort()
if discount > a[0]+b[0]:
    discount = a[0]+b[0]
print(discount)

Submission status: Accepted

Solution code:
def main():
    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):
        ticket = discount[i]
        tmp = A[ticket[0] - 1] + B[ticket[1] - 1] - ticket[2]
        if ans > tmp:
            ans = tmp

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def f():
    def getMin(A):
        minA = A[0]
        for a in A:
            minA = min(minA,a)
        return minA
    la, lb, lc = [int(s) for s in input().split()]
    A = [int(s) for s in input().split()]
    B = [int(s) for s in input().split()]
    mina = getMin(A)
    minb = getMin(B)
    ans = mina+minb
    for i in range(lc):
        x, y, c = [int(s) for s in input().split()]
        p = A[x-1]+B[y-1]-c
        ans = min(ans,p)
    print(ans)


f()

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

minA = min(Aa)
minB = min(Bb)

min_value = minA + minB
for x, y, c in XYCm:
  tot = Aa[x-1] + Bb[y-1] - c
  min_value = min(min_value, tot)
print(min_value)

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

answer=min(a)+min(b)

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

print(answer)

Submission status: Accepted

Solution code:
def resolve():
    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(max(ans, 0))


if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
a, b, m = map(int, input().split())
rei = list(map(int, input().split()))
den = list(map(int, input().split()))
cup = [tuple(map(int, input().split())) for _ in range(m)]

ans = 10 ** 9
for x, y, c in cup:
    ans = min(ans, rei[x-1] + den[y-1] - c)
ans = min(ans, min(rei) + min(den))
print(ans)

Submission status: Accepted

Solution code:


reizouNum, rangeNum, waribikiNum = map(int, input().split())

reizous = list(map(int, input().split()))
ranges = list(map(int, input().split()))

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



ans = 0
minreizou = min(reizous)
minrange = min(ranges)

ans = minreizou + minrange
# 割引券の額を総当たりする
for rei, rai, discount in waribikis:
    cost = reizous[rei-1] + ranges[rai-1] - discount
    ans = min(ans, cost)

print(ans)

Submission status: Accepted

Solution code:
import math
from collections import deque
def main():
    a,b,m = tuple([int(t)for t in input().split()])

    a_i = [int(t)for t in input().split()]
    b_i = [int(t)for t in input().split()]

    pairs = []
    for _ in range(m):
        pairs.append(tuple([int(t)for t in input().split()]))

    candidates = [min(a_i)+min(b_i)]

    for x,y,c in pairs:
        candidates.append(a_i[x-1]+b_i[y-1]-c)

    print(min(candidates))

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

print(ans)

Submission status: Accepted

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

res = 10**9
for i in range(M):
    x, y, c = map(int, input().split())
    x, y = x - 1, y - 1
    res = min(res, An[x] + Bn[y] - c)

a_m, b_m = min(An), min(Bn)

res = min(res, a_m + b_m)
print(res)

Submission status: Accepted

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

min_r = min(reizo)
min_d = min(densi)
max_all = min_r + min_d

for i in range(M):
  x, y, c = map(int,input().split())
  discount = reizo[x - 1] + densi[y -1] - c
  if max_all > discount:
    max_all = discount

print(max_all)

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())
    t = a[x - 1] + b[y - 1] - c
    if t < result:
        result = t
print(result)

Submission status: Accepted

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


def solve(A: int, B: int, M: int, a: "List[int]", b: "List[int]", x: "List[int]", y: "List[int]", c: "List[int]"):
    m = min(a) + min(b)
    for i in range(M):
        m = min(a[x[i]-1] + b[y[i]-1] - c[i], m)
    print(m)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(A)]  # type: "List[int]"
    b = [int(next(tokens)) for _ in range(B)]  # type: "List[int]"
    x = [int()] * (M)  # type: "List[int]"
    y = [int()] * (M)  # type: "List[int]"
    c = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        x[i] = int(next(tokens))
        y[i] = int(next(tokens))
        c[i] = int(next(tokens))
    solve(A, B, M, a, b, x, y, c)

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

amin = min(a)
bmin = min(b)

ans = amin + bmin

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

a_min = min(a)
b_min = min(b)

ans = a_min + b_min

x = 0
y = 1
c = 2
for t in ticket:
    set_price = a[t[x] - 1] + b[t[y] - 1] - t[c]
    ans = min(ans, set_price)

print(ans)

Submission status: Accepted

Solution code:
a, b, m = map(int, input().split())
ali = list(map(int, input().split()))
bli = list(map(int, input().split()))
xyc = [[int(i) for i in input().split()] for i in range(m)]
li = [0] * (m + 1)
for i in range(m):
    li[i] = ali[xyc[i][0] - 1] + bli[xyc[i][1] - 1] - xyc[i][2]
li[m] = min(ali) + min(bli)
print(min(li))

Submission status: Accepted

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

numOfA,numOfB,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:
# -*- coding: utf-8 -*-
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())
    tmp = a[x-1] + b[y-1] - c
    if tmp < ans:
        ans = tmp
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()))
xx = [0] * m
yy = [0] * m
cc = [0] * m
for i in range(m):
    xx[i], yy[i], cc[i] = map(int, input().split())

ans = min(aa) + min(bb)
for i in range(m):
    ans = min(ans, aa[xx[i] - 1]+ bb[yy[i] - 1] - cc[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 = 1145141919
for _ in range(m):
    x, y, c = map(int, input().split())
    if ans > A[x - 1] + B[y - 1] - c:
        ans = A[x - 1] + B[y - 1] - c
if min(A) + min(B) < ans:
    ans = min(A) + min(B)
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()))
#print(aa,bb)

mini=min(aa)+min(bb)

for _ in range(m):
  x,y,c=map(int,input().split())
  mini=min(mini,aa[x-1]+bb[y-1]-c)
print(mini)