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

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

a.sort()
b.sort()
cost = min(cost, a[0] + b[0])
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()))
xyc = [list(map(int, input().split())) for _ in range(m)]
result = [min(a)+min(b)]
for x, y, c in xyc:
    result.append(a[x-1]+b[y-1]-c)
print(min(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())
    x -= 1
    y -= 1
    p = a[x] + b[y] - c
    ans = min(ans, p)

print(ans)

Submission status: Accepted

Solution code:
def main():
    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()]
    ans = min(A) + min(B)
    for i in range(M):
        x, y, c = (int(i) for i in input().split())
        cur = A[x-1] + B[y-1] - c
        ans = min(ans, cur)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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


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 = 10**9+7

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

ans = min(ans,min(a)+min(b))
print(ans)

Submission status: Accepted

Solution code:
a, b, m = [ int(v) for v in input().split() ]
a_list = [ int(v) for v in input().split() ]
b_list = [ int(v) for v in input().split() ]
ans_list = []
for i in range(m):
    x, y, c = [ int(v) for v in input().split() ]
    ans_list.append(a_list[x - 1] + b_list[y - 1] - c)
a_list.sort()
b_list.sort()
ans_list.append(a_list[0] + b_list[0])
print(min(ans_list))

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_pr = min(A) + min(B)

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

    price = A[x-1] + B[y-1] - c
    min_pr = min(min_pr, price)

print(min_pr)

Submission status: Accepted

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

A, B, M = map(int, input().split())
As = list(map(int, input().split()))
Bs = list(map(int, input().split()))
xycs = [tuple(map(int, input().split())) for _ in range(M)]

ans = min(As) + min(Bs)
for x, y, c in xycs:
    x, y = x-1, y-1
    cost = As[x] + Bs[y] - c
#    print((x, y, c), cost)
    ans = min(ans, cost)

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

Submission status: Accepted

Solution code:
def examA():
    S = SI()
    if len(S)%2==1:
        print("No")
        return
    for i in range(len(S)//2):
        if S[i*2:i*2+2]!="hi":
            print("No")
            return
    print("Yes")
    return

def examB():
    a, b, M = LI()
    A = LI()
    B = LI()
    D = [LI()for _ in range(M)]
    ans = min(A) + min(B)
    for x,y,c in D:
        cur = A[x-1]+B[y-1]-c
        ans = min(ans,cur)
    print(ans)
    return

def examC():
    ans = 0
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**6)

if __name__ == '__main__':
    examB()

"""

"""

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())
  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())
*A, = map(int, input().split())
*B, = map(int, input().split())
coupons = [tuple(map(int, input().split())) for _ in range(M)]
ans = min(A) + min(B)
for x, y, c in coupons:
    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_array = [int(x) for x in input().split()]
b_array = [int(x) for x in input().split()]
array = [[int(x) for x in input().split()] for y in range(m)]
ans = min(a_array)+min(b_array)
for x, y, c in array:
    ans = min(a_array[x - 1] + b_array[y - 1] - c, ans)
print(ans)

Submission status: Accepted

Solution code:
a, b, m = map(int, input().split())
a2 = list(map(int, input().split()))
b2 = list(map(int, input().split()))
ans = min(a2) + min(b2)
for i in range(m):
    x, y, c = map(int, input().split())
    temp = a2[x - 1] + b2[y - 1] - 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()))
xyc = [tuple(map(int, input().split())) for i in range(M)]

ans = min(a) + min(b)

for x, y, c in xyc:
    x -= 1
    y -= 1
    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()))

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

Submission status: Accepted

Solution code:
import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7

a,b,m=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
xyc=[list(map(int,input().split())) for i in range(m)]

ans=float('inf')
ans=min(ans,min(a)+min(b))
for i in range(m):
    x,y,c=xyc[i]
    ans=min(ans,a[x-1]+b[y-1]-c)
print(ans)

Submission status: Accepted

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

lA, lB, M = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
XYZ = [list(map(int, input().split())) for _ in range(M)]

ans = min(A) + min(B)
dic = {}
for x, y, c in XYZ:
    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 = []
for _ in range(M):
	x, y, c = map(int, input().split())
	m_list.append((x, y, c))

total = min(a_list) + min(b_list)

for x, y, c in m_list:
	pay = a_list[x - 1] + b_list[y - 1] - c
	if pay < total:
		total = pay

print(total)

Submission status: Accepted

Solution code:
inpl = lambda: list(map(int,input().split()))
A, B, M = inpl()
a = inpl()
b = inpl()
ans = min(a) + min(b)
for _ in range(M):
    x, y, c = inpl()
    x -= 1
    y -= 1
    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()))
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
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return input().split()
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10

#solve
def solve():
    a, b, m = LI()
    a = LI()
    b = LI()
    xym = LIR(m)
    ans = min(a) + min(b)
    for x, y, m in xym:
        ans = min(ans, a[x - 1] + b[y - 1] - m)
    print(ans)
    return


#main
if __name__ == '__main__':
    solve()

Submission status: Accepted

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

w_mn = 10**9
for x,y,c in xyc:
    w_mn = min(w_mn, a[x-1] + b[y-1] - c)

ans = min(w_mn, min(a) + min(b))
print(ans)

Submission status: Accepted

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

ref = list(map(int,input().split()))
mic = list(map(int,input().split()))

ans = min(ref)+min(mic)


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

    if ref[x]+mic[y]-c < ans:
        ans = ref[x]+mic[y]-c

print(ans)

Submission status: Accepted

Solution code:
from sys import stdin
A,B,m = map(int,stdin.readline().rstrip().split())
a = list(map(int,stdin.readline().rstrip().split()))
b = list(map(int,stdin.readline().rstrip().split()))
li = [list(map(int,stdin.readline().rstrip().split())) for _ in range(m)]
mina = min(a)
minb = min(b)
goukei = min(a)+min(b)
for i,j,k in li:
    goukei = min(goukei,a[i-1]+b[j-1]-k)
print(goukei)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

INF = 10 ** 18

A, B, M = map(int, input().split())
a = [INF] + list(map(int, input().split()))
b = [INF] + list(map(int, input().split()))
xyc = [list(map(int, input().split())) for _ in range(M)]

answer = INF
for x, y, c in xyc:
    answer = min(answer, a[x] + b[y] - c)

a.sort()
b.sort()
answer = min(answer, a[0] + b[0])

print(answer)

Submission status: Accepted

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

ans = 10**10

for i in range(M):
	x,y,c = list(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:
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 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:
# coding: utf-8
# Your code here!

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
read = sys.stdin.read


#n,a = [int(i) for i in read().split()]



p,q,m = [int(i) for i in readline().split()]
a = [int(i) for i in readline().split()]
b = [int(i) for i in readline().split()]

ans = min(a)+min(b)

for _ in range(m):
    x,y,c = [int(i) for i in readline().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()))
ans=min(A)+min(B)
for i in range(m):
    x,y,c=map(int,input().split())
    x-=1
    y-=1
    cnt=A[x]+B[y]-c
    ans=min(ans,cnt)
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())
    temp = a[x-1] + b[y-1] - c
    if ans > temp:
        ans = temp
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 = min(aaa) + min(bbb)
for _ in range(m):
    x, y, c = map(int, input().split())
    x -= 1
    y -= 1
    tmp = aaa[x] + bbb[y] - c
    ans = min(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()))

MIN=min(A)+min(B)

for i in range(m):
    x,y,c=map(int,input().split())
    x-=1
    y-=1
    MIN=min(MIN,A[x]+B[y]-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()))
xyc = [list(map(int, input().split())) for _ in range(m)]

ans = min(a) + min(b)

for i in range(m):
    x = xyc[i][0] - 1
    y = xyc[i][1] - 1
    c = xyc[i][2]

    ans = min(ans, a[x] + b[y] - c)

print(ans)

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)]
ans = min(la)+min(lb)

for i,j,k in l:
    check = la[i-1]+lb[j-1]-k
    ans = min(ans,check)
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

A,B,m = inpl()
a = inpl()
b = inpl()
xyc = [inpl() for i in range(m)]
res = INF
for i in range(m):
    x,y,c = xyc[i]
    x -= 1; y -= 1
    tmp = a[x] + b[y] - c
    res = min(res, tmp)
res = min(res, min(a)+min(b))
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()))

ans = min(a) + min(b)
for _ in range(M):
    x, y, c = map(int, input().split())
    v = a[x - 1] + b[y - 1] - c
    ans = min(ans, v)
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())
aa = [int(x) for x in input().split()]
bb = [int(x) for x in input().split()]
ans = min(aa)+min(bb)
for i in range(m):
  x, y, c = map(int, input().split())
  key = aa[x-1]+bb[y-1]-c
  if key < ans:
    ans = key
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()))
    ans = min(a) + min(b)
    for _ in range(M):
        x, y, c = map(int, input().split())
        ans = min(ans, a[x-1] + b[y-1] - c)

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

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

wari = []
for i in range(M):
    t = list(map(int, input().split()))
    wari.append([t[0]-1, t[1]-1, t[2]])

# print(wari)

r = []

for x, y, c in wari:
    p = a[x] + b[y] - c
    r.append(p)
r.append(min(a)+min(b))


# print(r)
print(min(r))

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 = float("inf")
for x, y, c in xyc:
    x -= 1
    y -= 1
    cost = a[x] + b[y] - c
    ans = min(ans, cost)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

def main():
    A,B,M = inpm()
    a = inpl()
    b = inpl()
    ans = 10**20
    for _ in range(M):
        w,e,r = inpm()
        ans = min(ans,a[w-1]+b[e-1]-r)
    a.sort()
    ans = min(ans,min(a)+min(b))
    print(ans)
            
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# coding: utf-8
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = float("inf")
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 = 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)]

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

a.sort()
b.sort()
ans = min(ans, a[0] + b[0])

print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
a,b,m = map(int,input().split())
als = list(map(int,input().split()))
bls = list(map(int,input().split()))
xyc = [list(map(int,input().split())) for i in range(m)]
ans = min(als)+min(bls)
for x,y,c in xyc:
  ans = min(ans,als[x-1]+bls[y-1]-c)
print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(1000000000)
import math
from fractions import gcd
def lcm(a, b): return a * b // gcd(a, b)
from itertools import count, permutations
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7

def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok

def get_inv(n, modp):
    return pow(n, modp-2, modp)

def factorials_list(n, modp):    # 10**6
    fs = [1]
    for i in range(1, n+1):
        fs.append(fs[-1] * i % modp)
    return fs

def invs_list(n, fs, modp):     # 10**6
    invs = [get_inv(fs[-1], modp)]
    for i in range(n, 1-1, -1):
        invs.append(invs[-1] * i % modp)
    invs.reverse()
    return invs

def comb(n, k, modp):
    num = 1
    for i in range(n, n-k, -1):
        num = num * i % modp
    den = 1
    for i in range(2, k+1):
        den = den * i % modp
    return num * get_inv(den, modp) % modp

def comb_from_list(n, k, modp, fs, invs):   
    return fs[n] * invs[n-k] * invs[k] % modp

#

class UnionFindEx:
    def __init__(self, size):
        #正なら根の番号、負ならグループサイズ
        self.roots = [-1] * size
    def getRootID(self, i):
        r = self.roots[i]
        if r < 0:   #負なら根
            return i
        else:
            r = self.getRootID(r)
            self.roots[i] = r
            return r
    def getGroupSize(self, i):
        return -self.roots[self.getRootID(i)]
    def connect(self, i, j):
        r1, r2 = self.getRootID(i), self.getRootID(j)
        if r1 == r2:
            return False
        if self.getGroupSize(r1) < self.getGroupSize(r2):
            r1, r2 = r2, r1
        self.roots[r1] += self.roots[r2]    #サイズ更新
        self.roots[r2] = r1
        return True

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

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


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

    print(ans)



if __name__ == '__main__':
    main()

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()))
C = [list(map(int,input().split())) for i 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:
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 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
def input():
    return sys.stdin.readline()[:-1]
A,B,M=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
m=min(a)+min(b)
for i in range(M):
    x,y,c=map(int,input().split())
    t=a[x-1]+b[y-1]-c
    if m>t:
        m=t
print(m)

Submission status: Accepted

Solution code:
A, B, M = map(int, input().split())
ar = list(map(int, input().split()))
br = list(map(int, input().split()))
ans = min(ar) + min(br)
for i in range(M):
    x, y, c = map(int, input().split())
    ans = min(ar[x-1] + br[y-1] - c,ans)
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()))
XYC = []
min_cost = 10**10
for i in range(M):
    x,y,c = map(int,input().split())
    cost = As[x-1] + Bs[y-1]-c
    min_cost = min(min_cost,cost)
min_cost = min(min_cost,min(As)+min(Bs))
print(min_cost)

Submission status: Accepted

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

Submission status: Accepted

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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    A,B,M=MI()
    a=LI()
    b=LI()
    ans=min(a)+min(b)
    for i in range(M):
        x,y,c=MI()
        x-=1
        y-=1
        temp=a[x]+b[y]-c
        if ans>temp:
            ans=temp
    print(ans)

main()

Submission status: Accepted

Solution code:
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False
"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""
A,B,M = m()
a = l()
b = l()

po = min(a) + min(b)

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

print(po)

Submission status: Accepted

Solution code:
#設定
import sys
input = sys.stdin.buffer.readline

#ライブラリインポート
from collections import defaultdict

con = 10 ** 9 + 7
#入力受け取り
def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	A, B, M = getlist()
	a = getlist()
	b = getlist()
	am = min(a)
	bm = min(b)
	ans = am + bm
	for i in range(M):
		x, y, c = getlist()
		ans = min(ans, a[x - 1] + b[y - 1] - c)

	print(ans)
	


if __name__ == '__main__':
	main()

Submission status: Accepted

Solution code:
import sys

def solve():
    input = sys.stdin.readline
    A, B, M = map(int, input().split())
    A = [int(a) for a in input().split()]
    B = [int(b) for b in input().split()]
    minP = min(A) + min(B)
    for _ in range(M):
        x, y, c = map(int, input().split())
        minP = min(A[x-1] + B[y-1] - c, minP)
    print(minP)

    return 0

if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
def main():
    A, B, M = map( int, input().split())
    a = list( map( int, input().split()))
    b = list( map( int, input().split()))
    X = [ tuple( map( int, input().split())) for _ in range(M)]
    ans = min(a) + min(b)
    for x, y, c in X:
        if a[x-1] + b[y-1] - c < ans:
            ans = a[x-1] + b[y-1] - c
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Accepted

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

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