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:
import math
import string


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


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

Submission status: Accepted

Solution code:
A, B, M = [int(i) for i in input().split()]
ref = [int(i) for i in input().split()]
mic = [int(i) for i in input().split()]
cheap = min(ref) + min(mic)
for i in range(M):
  cp = [int(j) for j in input().split()]
  cheap = min([cheap, ref[cp[0]-1] + mic[cp[1]-1] - cp[2]])
print(cheap)

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())
cost = min(A) + min(B)
for i in range(m):
    cost = min(cost, A[X[i] - 1] + B[Y[i] - 1] - C[i])
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()))

min_ = min(A)+min(B)

for i in range(m):
  x, y, c = map(int, input().split())
  x, y = x-1, y-1
  if A[x]+B[y]-c <= 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()))
aa = min(a)
bb = min(b)
aabb = aa+bb
ans = []
ans.append(aabb)
for i in range(m):
    x, y, c = map(int, input().split())
    ans.append(a[x-1]+b[y-1]-c)
print(min(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()))
ans=min(la)+min(lb)
for i in range(m):
  x,y,c=map(int,input().split())
  ans=min(ans,la[x-1]+lb[y-1]-c)










print(ans)

Submission status: Accepted

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

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

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

ma = min(a)
mb = min(b)

cost = ma + mb

for i in range(m):
    x = xyc[i][0]
    y = xyc[i][1]
    c = xyc[i][2]
    cost = min( cost, a[x-1] + b[y-1] - c )

print(cost)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
import math
import heapq
import bisect
from collections import defaultdict, Counter, deque
import sys
# input = sys.stdin.buffer.readline
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))

class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)
        self.size = [1] * (n+1)

    # 検索
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    # 併合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
            self.size[y] += self.size[x]
        else:
            self.par[y] = x
            self.size[x] += self.size[y]
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    # 同じ集合に属するか判定
    def same_check(self, x, y):
        return self.find(x) == self.find(y)

    def update_all(self):
        n = len(self.par)
        for i in range(n):
            self.par[i] = self.find(i)

def main():
    a,b,m = getList()
    anums = getList()
    bnums = getList()
    ans = min(anums) + min(bnums)
    for i in range(m):
        x,y,c = getList()
        tmp = anums[x-1] + bnums[y-1] - c
        if ans > tmp:
            ans = tmp

    print(ans)


if __name__ == "__main__":
    main()

"""
10
203941992 742164984
670850202 743524472
687298546 744891559
676493045 744182895
385467254 742631752
740505911 744926772
425723256 743348462
225362543 742332848
399450535 742706299
563528474 743419738
"""

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):
    cnt1, cnt2, cnt3 = map(int, input().split())
    x.append(cnt1)
    y.append(cnt2)
    c.append(cnt3)
ans = 10**9+7

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

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

num = min(a) + min(b)
if num < ans:
    ans = num

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

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:
import sys
input = sys.stdin.buffer.readline


# mod=10**9+7
# rstrip().decode('utf-8')
# map(int,input().split())
# import numpy as np

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

ans=99999999999
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 copy
A,B,M=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
q=[list(map(int,input().split())) for _ in range(M)]
a1=copy.deepcopy(a)
b1=copy.deepcopy(b)
a1.sort()
b1.sort()
min=a1[0]+b1[0]
ca=0
for i in range(M):
 try:
  ca=a[q[i][0]-1]+b[q[i][1]-1]-q[i][2]
 except:
  ca=float("inf")
 if ca<min:
  min=ca
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 = 100000000
for i in range(M):
    x = list(map(int,input().split()))
    # print(x)
    ans = min(a[x[0]-1]+b[x[1]-1]-x[2],ans)
    # x.append(list(map(int,input().split())))
ans = min(min(a) + min(b),ans)#割引券を使わずに最安値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()))
xyc = []
for i in range(m):
    xyc.append(list(map(int, input().split())))

x = 0
y = 1
c = 2

price = []

for i in range(m):
    price.append(a[xyc[i][x]-1] + b[xyc[i][y]-1] - xyc[i][c])

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

Submission status: Accepted

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

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

disc = [0] * M
for i in range(M):
  disc[i] = a[x[i]-1] + b[y[i]-1] - c[i]

D = min(a) + min(b)

print(min(min(disc), D))

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

a.sort()
b.sort()

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

print (ans)

Submission status: Accepted

Solution code:
res = -1
A,B,M = list(map(int,input().split()))
a = list(map(int,input().split()))
b = list(map(int,input().split()))
amin = 100000
bmin = 100000
cmin = amin + bmin
for i in a:
  if amin > i:
    amin = i
for i in b:
  if bmin > i:
    bmin = i
res = amin + bmin
for i in range(M):
  xi,yi,ci = list(map(int,input().split()))
  c = a[xi-1] + b[yi-1] - ci
  if cmin > c:
    cmin = c

if res > cmin:
  print(cmin)
else:
  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)
X = []
for _ in range(m):
    x, y, c = map(int, input().split())
    ans = min(ans, A[x-1]+B[y-1]-c)

print(ans)

Submission status: Accepted

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

ans = min(a) + min(b)

for t in T:
    ans = min(ans, a[t[0] - 1] + b[t[1] - 1] - t[2])

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 _ in range(m)]

da = {}
for i in range(a):
    da[i+1] = al[i]
db = {}
for i in range(b):
    db[i+1] = bl[i]

res = min(al)+min(bl)
for x,y,c in xyc:
    res = min(res, da[x]+db[y]-c)

print(res)

Submission status: Accepted

Solution code:
def input_int_list():
    return [int(thing) for thing in input().split(" ")]

A,B,M=input_int_list()
a_list=input_int_list()
b_list=input_int_list()
discounts=[input_int_list() for i in range(M)]

min_without_discount=min(a_list)+min(b_list)

set_price_with_discount=[a_list[di[0]-1]+b_list[di[1]-1]-di[2] for di in discounts]
min_discounted=min(set_price_with_discount)
print(min(min_discounted,min_without_discount))

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

res = 10**9
for x,y,c in XYC:
    res = min(res,a[x-1]+b[y-1]-c)
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()))
mn = min(a) + min(b)
for _ in range(m):
  xi,yi,ci = map(int,input().split())
  d = a[xi-1] + b[yi-1] - ci 
  if d < mn:
    mn = d
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()))
x=[0]*M
y=[0]*M
c=[0]*M
for i in range(M):
    x[i],y[i],c[i]=map(int,input().split())
mn=min(a)+min(b)
for i in range(M):
    if mn>(a[x[i]-1]+b[y[i]-1]-c[i]):
        mn=a[x[i]-1]+b[y[i]-1]-c[i]
print(mn)

Submission status: Accepted

Solution code:
A,B,M = [int(x) for x in input().split()]
A_list = [int(x) for x in input().split()]
B_list = [int(y) for y in input().split()]
discount = []
min = 200000
for _ in range(M):
  case = [int(x) for x in input().split()]
  discount.append(case)
 
min_a = sorted(A_list)[0]
min_b = sorted(B_list)[0]
 
for i in range(M):
  temp = A_list[discount[i][0]-1] + B_list[discount[i][1]-1] - discount[i][2]
  if temp < min:
    min = temp
    
if min_a + min_b > min:
  print(min)
else:
  print(min_a + min_b)

Submission status: Accepted

Solution code:
A,B,M = [int(x) for x in input().split()]
A_list = [int(x) for x in input().split()]
B_list = [int(y) for y in input().split()]
discount = []
min = 1000000
for _ in range(M):
  case = [int(x) for x in input().split()]
  discount.append(case)
 
min_a = sorted(A_list)[0]
min_b = sorted(B_list)[0]
 
for i in range(M):
  temp = A_list[discount[i][0]-1] + B_list[discount[i][1]-1] - discount[i][2]
  if temp < min:
    min = temp
    
if min_a + min_b > min:
  print(min)
else:
  print(min_a + min_b)

Submission status: Accepted

Solution code:
def b_nice_shopping():
    A, B, M = [int(i) for i in input().split()]
    refrigerator = [int(i) for i in input().split()]
    microwave = [int(i) for i in input().split()]
    discount_ticket = [[int(i) for i in input().split()] for j in range(M)]

    # 最も安い冷蔵庫と電子レンジをそれぞれ買うか、割引券を使える組み合わせを買うか
    ans = min(refrigerator) + min(microwave)
    for x, y, c in discount_ticket:
        ans = min(ans, refrigerator[x - 1] + microwave[y - 1] - c)
    return ans

print(b_nice_shopping())

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):
    coupons.append(list(map(int, input().split())))

a_min = min(As)
b_min = min(Bs)

best_sum = a_min+b_min
coupons_sums = []
for l in coupons:
    coupons_sums.append(As[l[0]-1] + Bs[l[1]-1] - l[2])
    
for coupons_sum in coupons_sums:
    if best_sum > coupons_sum:
        best_sum = coupons_sum

print(best_sum)

Submission status: Accepted

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

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

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

ans = min(A) + min(B)
for x, y, c in XYC:
    cost = A[x - 1] + B[y - 1] - c
    ans = min(ans, cost)

print(ans)

Submission status: Accepted

Solution code:
a,b,m=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
AA=sorted(A)
BB=sorted(B)
ans=AA[0]+BB[0]
for i in range(m):
  x,y,c=map(int,input().split())
  d=A[x-1]+B[y-1]-c
  if d<ans:
    ans=d
print(ans)

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    (A, B, M) = tuple(map(int, input().split()))
    rf_prices = list(map(int, input().split()))
    rg_prices = list(map(int, input().split()))
    d_tickets = [list(map(int, input().split())) for _ in range(M)]
    min_with_ticket = min([rf_prices[t[0]-1]+rg_prices[t[1]-1]-t[2] for t in d_tickets])
    min_with_none_ticket = min(rf_prices)+min(rg_prices)
    print(min(min_with_none_ticket, min_with_ticket))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
A, B, M = map(int, input().split(' '))
a = [int(x) for x in input().split(' ')]
b = [int(x) for x in input().split(' ')]
min = 10000000
for i in range(M):
    x, y, c = map(int, input().split(' '))
    price = a[x - 1] + b[y - 1] - c
    if price < min:
        min = price
minA = minB = 1000000
for e in a:
    if e < minA:
        minA = e
for e in b:
    if e < minB:
        minB = e

if minA + minB < min:
    print(minA + minB)
else:
    print(min)

Submission status: Accepted

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

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

    a_list = list(map(int, input().split(' ')))
    b_list = list(map(int, input().split(' ')))


    price_list = 2*10**5
    for i in range(M):
        temp = list(map(int, input().split(' ')))
        if price_list > a_list[temp[0]-1] + b_list[temp[1]-1] - temp[2]:
            price_list = a_list[temp[0]-1] + b_list[temp[1]-1] - temp[2]

    lower = min(a_list) + min(b_list)
    if lower < price_list:
        print(lower)
    else:
        print(price_list)

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

Submission status: Accepted

Solution code:
A,B,M = map(int, input().split(' '))
priceA = list(map(int, input().split(' ')))
priceB = list(map(int, input().split(' ')))
minPrice = min(priceA) + min(priceB)

for i in range(M):
    ai,bi,discount = list(map(int, input().split(' ')))
    sum = (priceA[ai-1] + priceB[bi-1] - discount)
    if minPrice > sum:
      minPrice = sum
else:      
    print(minPrice)

Submission status: Accepted

Solution code:
import numpy as np

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

num = min(a) + min(b)

for _ in range(M):
    m1,m2,m3 = map(int,input().split())
    res = a[m1-1]+b[m2-1] - m3
    num = min(num,res)

print(num)

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 numpy as np

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

num = int(min(a)) + int(min(b))

for _ in range(M):
    m1,m2,m3 = map(int,input().split())
    res = int(a[m1-1])+int(b[m2-1]) - m3
    num = min(num,res)

print(num)

Submission status: Accepted

Solution code:
a,b,m,*L=map(int,open(0).read().split());K=L[a+b:];I=L[a:a+b]
print(min(min(I)+min(L[:a]),min(-z+L[x-1]+I[y-1]for x,y,z in zip(*[iter(K)]*3))))

Submission status: Accepted

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

res=min(Ai)+min(Bi)
for j in range(M):
  s=list(map(int,input().split()))
  if Ai[s[0]-1]+Bi[s[1]-1]-s[2]<res:
    res=Ai[s[0]-1]+Bi[s[1]-1]-s[2]
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()))
x=[]
for i in range(m):
    x.append(list(map(int,input().split())))

ans=min(a)+min(b)
for i in range(m):
    ans=min(ans,a[x[i][0]-1]+b[x[i][1]-1]-x[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()))
a1=sorted(a)
b1=sorted(b)
mini=a1[0]+b1[0]
for i in range(M):
    x,y,z=map(int,input().split())
    price=a[x-1]+b[y-1]-z
    if mini>price:
        mini=price
print(mini)

Submission status: Accepted

Solution code:
import numpy as np

A,B,M = list(map(int,input().split()))
valueA = list(map(int, input().split()))
#print(valueA)
valueB = list(map(int, input().split()))
#print(valueB)
tickets = np.zeros((M ,3))
for i in range(M):
    tickets[i,:] =  list(map(int, input().split()))
x1 = int(tickets[0,0])
y1 = int(tickets[0,1])
c1 = int(tickets[0,2])
min_ticket = valueA[x1-1] + valueB[y1-1] - c1
if M != 1:
    for i in range(1,M):
        xi = int(tickets[i,0])
        yi = int(tickets[i,1])
        ci = int(tickets[i,2])
        value = valueA[xi-1] + valueB[yi-1] - ci
        if value < min_ticket:
            min_ticket = value
"""
min_itself = valueA[0] + valueB[0]
# 全部やってるから時間かかる
for i in range(A):
    for j in range(B):
        value = valueA[i] + valueB[j]
        if value < min_itself:
            min_itself = value
min_all = min(min_itself, min_ticket)
"""
minA = min(valueA)
minB = min(valueB)
min_itself = minA + minB
min_all = min(min_itself, min_ticket)
print(min_all)

Submission status: Accepted

Solution code:
INF = 10 ** 18

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

print(answer)

Submission status: Accepted

Solution code:
import sys

counts = list(map(int,input().split()))
colors = list(map(int,input().split()))
hots = list(map(int,input().split()))

ticketCount = counts[2]

minPrice = sys.maxsize
# first. get disscount consider price
for i in range(ticketCount):
  values = input().split()
  x = int(values[0])
  y = int(values[1])
  dissPrice = int(values[2])
  colorPrice = colors[x-1]
  hotsPrice = hots[y-1]
  validPrice =  colorPrice + hotsPrice - dissPrice
  if minPrice > validPrice:
    minPrice = validPrice

max_color = min(colors)
max_color_idx = colors.index(max_color)
max_hots = min(hots)
max_hots_idx = hots.index(max_hots)
validPrice = max_color + max_hots
if minPrice > validPrice:
  minPrice = validPrice
print(str(minPrice))

Submission status: Accepted

Solution code:
# B - Nice Shopping
def main():
    A, B, M, *ABX = map(int, open(0).read().split())
    fridges, microwaves, X = ABX[:A], ABX[A : A + B], ABX[A + B :]
    with_tickets = min(
        fridges[x - 1] + microwaves[y - 1] - c for x, y, c in zip(*[iter(X)] * 3)
    )
    without_tickets = min(fridges) + min(microwaves)
    print(min(with_tickets, without_tickets))


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

ans = min(a) + min(b)

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

print(ans)

Submission status: Accepted

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

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

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

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())
    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())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
l=[]
for i in range(m):
        l.append(list(map(int, input().split())))
sa=sorted(a)
sb=sorted(b)
ans=sa[0]+sb[0]
for i in range(m):
        sm= a[l[i][0]-1] + b[l[i][1]-1] - l[i][2]
        if ans > sm:
                ans=sm
print(ans)

Submission status: Accepted

Solution code:
na,nb,nm =  map(int, (input().split()))

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

mina = a[0]
minb = b[0]
for i in range(na):
    if a[i] < mina :
        mina = a[i]
for j in range(nb):
    if b[j] < minb :
        minb = b[j]
min = mina + minb

#  m入力
for k in range(nm):
    i,j,disc = map(int, input().split())
    if min > a[i-1]+b[j-1]-disc:
        min = a[i-1]+b[j-1]-disc

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 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_price = list(map(int,input().split()))
b_price = list(map(int,input().split()))
coupon = []
for i  in range(m):
    coupon.append(list(map(int,input().split())))
    # 例：[[1, 1, 5], [1, 1, 10]]


def get_min(a_price, b_price, coupon):
    minprice= min(a_price)+min(b_price)
    for k in range(m):
        aindex  = coupon[k][0]-1
        bindex  = coupon[k][1]-1
        sale = coupon[k][2]
        price = a_price[aindex]+b_price[bindex]-sale
        if price < minprice:
            minprice = price
    return minprice

print(get_min(a_price, b_price, coupon))

Submission status: Accepted

Solution code:
a,b,m=map(int,input().split())
ai=list(map(int, input().split()))
bi=list(map(int, input().split()))
sm=[list(map(int, input().split())) for _ in range(m)]
k=min(ai)+min(bi)

for x in range(m):
    
    l=ai[sm[x][0]-1]+bi[sm[x][1]-1]-sm[x][2]
    k=min(k,l)

print(k)

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=[[int(i) for i in input().split()] for i in range(m)]
ans=min(A)+min(B)

for s,t,u in x:
    tmp=A[s-1]+B[t-1]-u
    ans=min(ans,tmp)
print(ans)

Submission status: Accepted

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

ans = min(ref) + min(ran)

for i in range(m):
  t = list(map(int,input().split()))
  p = t[0] 
  q = t[1]
  c = t[2]
  if (len(ref) >= p and len(ran) >= q):
    if ref[p - 1] + ran[q - 1] - c < ans:
      ans = ref[p - 1] + ran[q - 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()))

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

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

### そもそもクーポン使わない最小の組み合わせを初期値とする
smallest = min(a) + min(b)
for i in range(M):
    x, y, c = list(map(int, input().split()))
    x -= 1
    y -= 1
    price = a[x] + b[y] - c
    smallest = min(smallest, price)
print(smallest)

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())
    
cal_1=min(a)+min(b)
cal_2=[0]*M

for i in range(M):
    cal_2[i]=a[x[i]-1]+b[y[i]-1]-c[i]
    
cal_3=min(cal_2)

if cal_1>=cal_3:
    print(cal_3)
else:
    print(cal_1)

Submission status: Accepted

Solution code:
_,a,b,*t=[list(map(int,i.split())) for i in open(0)]
n=min(a)+min(b)
for x,y,c in t:n=min(n,a[x-1]+b[y-1]-c)
print(n)

Submission status: Accepted

Solution code:
_,a,b,*t = [list(map(int,i.split())) for i in open(0)]
n=min(a)+min(b)
for x,y,c in t:n=min(n,a[x-1]+b[y-1]-c)
print(n)

Submission status: Accepted

Solution code:
_,a,b,*t = [list(map(int,t.split())) for t in open(0)]
n=min(a)+min(b)
for x,y,c in t:
  n=min(n,a[x-1]+b[y-1]-c)
print(n)

Submission status: Accepted

Solution code:
_,a,b,*t = [list(map(int,i.split())) for i in open(0)]
n=min(a)+min(b)
for x,y,c in t:
  n=min(n,a[x-1]+b[y-1]-c)
print(n)

Submission status: Accepted

Solution code:
x = input().split()
A = int(x[0])
B = int(x[1])
M = int(x[2])
a = input().split()
b = input().split()

a = [int(l) for l in a]
b = [int(l) for l in b]

c = min(a) + min(b)

for i in range(M):
    z = input().split()
    c1 = a[int(z[0])-1] + b[int(z[1])-1] - int(z[2])
    if c > c1:
        c = c1

print(c)

Submission status: Accepted

Solution code:
_,a,b,*t=[list(map(int,t.split()))for t in open(0)];print(min([min(a)+min(b)]+[a[x-1]-c+b[y-1]for x,y,c in t]))

Submission status: Accepted

Solution code:
_,a,b,*t=[list(map(int,t.split()))for t in open(0)]
m=min(a)+min(b)
for x,y,c in t:m=min(m,a[x-1]+b[y-1]-c)
print(m)

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

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())
  i-=1; j-=1
  ans=min(ans,A[i]+B[j]-c)
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()))
xyclist = [list(map(int, input().split())) for _ in range(M)]
am, bm = min(alist), min(blist)
ans = am + bm

for x, y, c in xyclist:
    ans = min(ans, alist[x-1]+blist[y-1]-c)
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
a,b,m = map(int, input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
M = []
for _ in range(m):
  M.append(list(map(int,input().split())))
  
min_price = min(A) + min(B)
for s in M:
  price = A[s[0]-1] + B[s[1]-1] - s[2]
  if min_price > price:
    min_price = price
    
print(min_price)