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 sys

readline = sys.stdin.readline

def main():
    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 _ in range(M):
        x, y, c = map(int, readline().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())
al=list(map(int,input().split()))
bl=list(map(int,input().split()))
xyc=[list(map(int,input().split())) for _ in range(m)]

ans=min(al)+min(bl)
for i in range(m):
    tmp=0
    tmp=al[xyc[i][0]-1]+bl[xyc[i][1]-1]-xyc[i][2]
    ans=min(ans,tmp)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
A,B,M=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
xyc=[list(map(int,input().split()))for i in range(M)]
ans=min(a)+min(b)
for i in range(M):
    tmp = a[xyc[i][0]-1]+b[xyc[i][1]-1]-xyc[i][2]
    if ans > tmp:
        ans=tmp
print(ans)

Submission status: Accepted

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

ans = min(a) + min(b)
for _ in range(M):
    x, y, c = map(int, input().split())
    if a[x-1]+b[y-1]-c < ans:
        ans = a[x-1]+b[y-1]-c
    else:
        pass
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:
def main():
    _,_,m = map(int,input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))

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

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

result = min(s, c_min)
print(result)

Submission status: Accepted

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

Submission status: Accepted

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

ans = min(a) + min(b)

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

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

print(ans)

Submission status: Accepted

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

ans = 999999

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

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

print(ans)

Submission status: Accepted

Solution code:
import sys

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

a = list(map(int, sys.stdin.readline().rsplit()))
b = list(map(int, sys.stdin.readline().rsplit()))

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:
#S= str(input())
#T= str(input())
#N = int(input())
A,B,M= map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C=10**6
for i in range(M):
    x,y,c= map(int,input().split())
    cost = A[x-1] + B[y-1] - c
    if cost<=C:
        C=cost
if min(A)+min(B)<=C:
    C=min(A)+min(B)
print(C)

Submission status: Accepted

Solution code:
a, b, m = list(map(int, input().split()))
refrigerator_list = list(map(int, input().split()))
microwave_list = list(map(int, input().split()))
coupon_list = list()
for _ in range(m):
    coupon_list.append(list(map(int, input().split())))

ans = min(refrigerator_list) + min(microwave_list)
for coupon in coupon_list:
    ans = min(refrigerator_list[coupon[0] - 1] + microwave_list[coupon[1] - 1] - coupon[2], ans)

print(ans)

Submission status: Accepted

Solution code:
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = [list(map(int, input().split())) for _ in range(M)]
buy = [min(a)+min(b)]
for i in range(M):
  C = a[c[i][0]-1]+b[c[i][1]-1]-c[i][2]
  buy.append(C)
print(min(buy))

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

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
    M = min(M,t)

print(M)

Submission status: Accepted

Solution code:
from collections import defaultdict
import numpy as np

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

ans = a.min() + b.min()

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

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

print(mi)

Submission status: Accepted

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

X=list()
Y=list()
C=list()
for i in range(M):
  x,y,c=map(int,input().split())
  X.append(x)
  Y.append(y)
  C.append(c)
ans=list()
for i in range(M):
  xx=int(X[i])-1
  yy=int(Y[i])-1
  cc=int(C[i])
  num=int(A[xx])+int(B[yy])-cc
  ans.append(num)
Ans=int(min(ans))
print(min(ab,Ans))

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline

def main():
    ans = 10**5 * 2
    A, B, M = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    ans = sorted(a)[0] + sorted(b)[0]
    
    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)

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()))
xyc = [map(int, input().split()) for _ in range(M)]
x, y, c = [list(x) for x in zip(*xyc)]

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

print(m)

Submission status: Accepted

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

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

ans = min(a_l) + min(b_l)
for x, y, c in xyc:
    ans = min(ans, a_l[x-1]+b_l[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()))

pr = []
for i in range(M):
    X = list(map(int, input().split()))  #リスト

    pr.append(a[X[0]-1] + b[X[1]-1] - X[2])

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

Submission status: Accepted

Solution code:
def resolve():
    a, b, m = map(int, input().split())
    a_s = [int(i) for i in input().split()]
    b_s = [int(i) for i in input().split()]

    min_cost = min(a_s) + min(b_s)
    for _ in range(m):
        a_i, b_i, c_i = map(int, input().split())
        cost = a_s[a_i-1] + b_s[b_i-1] - c_i
        if cost < min_cost:
            min_cost = cost

    print(min_cost)


resolve()

Submission status: Accepted

Solution code:
a,b,m=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
xyc=[list(map(int,input().split())) for _ in range(m)]
a1=sorted(a)
b1=sorted(b)
price=a1[0]+b1[0]
ans=float('inf')
for i in range(m):
    x=a[xyc[i][0]-1]+b[xyc[i][1]-1]-xyc[i][2]
    if x<ans:
        ans=x
print(min(price,ans))

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
coupon = [list(map(int, input().split())) for _ in range(M)]
a_min, b_min = min(a), min(b)
discount = []
for i in range(M):
    discount.append(a[coupon[i][0] - 1] + b[coupon[i][1] - 1] - coupon[i][2])
if a_min + b_min < min(discount):
    print(a_min + b_min)
else:
    print(min(discount))

Submission status: Accepted

Solution code:
a, b, m = map(int, input().split())
lsa = list(map(int, input().split()))
lsb = list(map(int, input().split()))
cost = min(lsa) + min(lsb)
for i in range(m):
    x, y, c = map(int, input().split())
    cost2 = lsa[x - 1] + lsb[y - 1] - c
    if cost2 < cost:
        cost = cost2

print(cost)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

min = min(a)+min(b)

for i in range(M):
    c =list(map(int,input().split()))
    s = a[c[0]-1]+b[c[1]-1]-c[2]
    min = (s if s < min else min)

print(min)

Submission status: Accepted

Solution code:

# inputを高速化する。
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()))

ans = min(As) + min(Bs)

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

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

minP = min(a) + min(b)

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

print(minP)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a,b,m = map(int,input().split())
al = list(map(int,input().split()))
bl = list(map(int,input().split()))
disc = [[]]*m
for i in range(m):
  disc[i] = list(map(int,input().split()))
mina = 100000
minb = 100000
for i in range(a):
  mina = min(mina,al[i])
for i in range(b):
  minb = min(minb,bl[i])
total = mina+minb
for i in range(m):
  total = min(total,al[disc[i][0]-1]+bl[disc[i][1]-1]-disc[i][2])
print(total)

Submission status: Accepted

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

p=min(a)+min(b)

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

print(p)

Submission status: Accepted

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

Submission status: Accepted

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

prm_min = min(la) + min(lb)

lcost = list()
for i in range(M):
    x, y, c = map(int, input().split())
    lcost.append(la[x-1] + lb[y-1] - c)

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

amin = min(a)
bmin = min(b)
ans = amin + bmin
for c_ in c:
    tmp = a[c_[0]-1] + b[c_[1]-1] - c_[2]
    ans = min(ans,tmp)

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

ans=min(As)+min(Bs)
for l in List:
  candidate=As[l[0]-1]+Bs[l[1]-1]-l[2]
  ans = min(ans, candidate)
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()))
low=min(a)+min(b)
cost=[]
for i in range(M):
  x,y,c=map(int,input().split())
  cost.append(a[x-1]+b[y-1]-c)
  
print(min(low,min(cost)))

Submission status: Accepted

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

# 割引券を使用しない場合は各品の最低金額合計が解となる
ans = min(a) + min(b)

# 割引券を使用して安くなるケースがないか調べる
for _ 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())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
x = list()
y = list()
c = list()
for i in range(M):
    _x, _y, _c = map(int, input().split())
    x.append(_x-1)
    y.append(_y-1)
    c.append(_c)
ans = min(a) + min(b)
for i in range(M):
    ans = min(ans, a[x[i]]+b[y[i]]-c[i])
print(ans)

Submission status: Accepted

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

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

mi = min(a) + min(b)

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

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 = 123456789012345

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def solve():
    A,B, M = map(int, input().split())
    a_kind = list(map(int, input().split()))
    b_kind = list(map(int, input().split()))
    Coupon =  [list(map(int, input().split())) for _ in range(M)]
    ans = min(a_kind) + min(b_kind)

    for x,y,disc in Coupon:
        ans = min(ans, a_kind[x-1] + b_kind[y-1] - disc)
    print(ans)



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

ans = min(a) + min(b)

for i in range(M):
  ans = min(ans, a[m[i][0]-1] + b[m[i][1]-1] - m[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()))
c=[min(a)+min(b)]
for i in range(M):
    a1,b1,c1 =map(int,input().split())
    d=a[a1-1]+b[b1-1]-c1
    c.append(d)
print(min(c))

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

X=[]
Y=[]
C=[]
for m in range(M):
  x,y,c=map(int,input().split())
  X.append(x)
  Y.append(y)
  C.append(c)
no_coupon=min(a)+min(b)

sum=[]
for i in range(M):
  sum.append(a[X[i]-1]+b[Y[i]-1]-C[i])

with_coupon=min(sum)
print(min(no_coupon,with_coupon))

Submission status: Accepted

Solution code:
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))
## dp ##
def DD2(d1,d2,init=0): return [[init]*d2 for _ in range(d1)]
def DD3(d1,d2,d3,init=0): return [DD2(d2,d3,init) for _ in range(d1)]
## math ##
def to_bin(x: int) -> str: return format(x, 'b') # rev => int(res, 2)
def to_oct(x: int) -> str: return format(x, 'o') # rev => int(res, 8)
def to_hex(x: int) -> str: return format(x, 'x') # rev => int(res, 16)
MOD=10**9+7
def divc(x,y) -> int: return -(-x//y)
def divf(x,y) -> int: return x//y
def gcd(x,y):
    while y: x,y = y,x%y
    return x
def lcm(x,y): return x*y//gcd(x,y)
def enumerate_divs(n):
    """Return a tuple list of divisor of n"""
    return [(i,n//i) for i in range(1,int(n**0.5)+1) if n%i==0]
def get_primes(MAX_NUM=10**3):
    """Return a list of prime numbers n or less"""
    is_prime = [True]*(MAX_NUM+1)
    is_prime[0] = is_prime[1] = False
    for i in range(2, int(MAX_NUM**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i*2, MAX_NUM+1, i):
            is_prime[j] = False
    return [i for i in range(MAX_NUM+1) if is_prime[i]]
## libs ##
from itertools import accumulate as acc
from collections import deque, Counter
from heapq import heapify, heappop, heappush
from bisect import bisect_left

#======================================================#

def main():
    a, b, m = MII()
    aa = MII()
    bb = MII()
    q = [MII() for _ in range(m)]
    minv = min(aa) + min(bb)
    for x,y,c in q:
        minv = min(minv, aa[x-1]+bb[y-1]-c)
    print(minv)

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

# 割引券の金額を1つずつ確認し、①よりも低い場合に入れ替える
for _ in range(M):
    x, y, c = map(int, input().split())
    price = a[x - 1] + b[y - 1] - c
    ans = min(ans, price)

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

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

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

Submission status: Accepted

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

na,nb,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
    if tmp<ans:
        ans=tmp
print(ans)

Submission status: Accepted

Solution code:
import numpy as np

def multi_input():
    return map(int, input().split())

A, B, M = multi_input()
a = list(map(int, input().split()))
b = list(map(int, input().split()))
C = [list(map(int, input().split())) for i in range(M)]

mn = np.inf
for x, y, c in C:
    mn = min(mn, a[x-1]+b[y-1]-c)
mn = min(mn, min(a)+min(b)) 
print(mn)

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()))
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:
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    a,b,m=map(int, input().split())
    la=list(map(int,input().split()))
    lb=list(map(int,input().split()))
    lm=[list(map(int,input().split())) for i in range(m)]
    nowari=min(la)+min(lb)
    warians=10**10
    for i in range(m):
        wari=la[(lm[i][0])-1]+lb[(lm[i][1])-1]-lm[i][2]
        if wari<warians:
            warians=wari
    print(min(nowari,warians))
resolve()

Submission status: Accepted

Solution code:
import itertools 

line1 = input().split()
rei = input().split()
rei =list(map(int,rei))
den =input().split()
den =list(map(int,den))
cupon =[list(map(int,input().split())) for i in range(int(line1[2]))]

rei_mi = min(rei)
den_mi =min(den)

no_total =rei_mi +den_mi

for s in range(int(line1[2])):
  yes_total =int(rei[cupon[s][0]-1]) +int(den[cupon[s][1]-1]) - cupon[s][2]
  if no_total > yes_total:
    no_total =yes_total
print(no_total)

Submission status: Accepted

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

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

Submission status: Accepted

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

count=[]
count.append(min(a_1)+min(b_1))

for k in range(M):
    count.append(a_1[L[k][0]-1]+b_1[L[k][1]-1]-L[k][2])

print(min(count))

Submission status: Accepted

Solution code:
A, B, M = list(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 = list(map(int, input().split()))
    cost = a_list[x - 1] + b_list[y - 1] - c
    if cost < ans:
        ans = cost
        
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()))
L=[[int(j) for j in input().split()] for i in range(m)]

sortsec = lambda val : val[2]
L1=sorted(L,key=sortsec,reverse=True)
cnt=10**8
for i,j,k in L1:
    num=A[i-1]+B[j-1]-k
    cnt=min(cnt,num)
num=min(A)+min(B)
print(min(num,cnt))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

min_no_discount = min(as_) + min(bs)

min_discount = 1e20
for x, y, c in xyc:
    min_discount = min(min_discount, as_[x - 1] + bs[y - 1] - c)

print(min(min_discount, min_no_discount))

Submission status: Accepted

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

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

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

min_ = min(min(C), min(A) + min(B))
print(min_)

Submission status: Accepted

Solution code:
import numpy as np
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()))

res = np.min(a) + np.min(b)

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

print(res)

Submission status: Accepted

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

Submission status: Accepted

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

smallest = min(a) + min(b)

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

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()))
minnum = float('inf')
for i in range(M):
    x, y, z = map(int, input().split())
    minnum = min(a[x-1] + b[y-1] - z, minnum)

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

Submission status: Accepted

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

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

def readInts():
  return list(map(int,input().split()))
def main():
    a,b,m = readInts()
    A = readInts()
    B = readInts()
    ans = float('inf')
    for i in range(m):
        x,y,c = readInts()
        x -=1
        y -=1
        ans = min(ans,A[x] + B[y] - c)
    # Aの商品の中で1番最小のやつを買うだけでもいいかもしれない
    # Bの商品の中で1番最小のやつを買うだけでもいいかもしれない
    ans = min(ans,min(A) + min(B))
    print(ans)
if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
A, B, M = (int(x) for x in input().split())
al = [int(x) for x in input().split()]
bl = [int(x) for x in input().split()]
ml = [[int(x) for x in input().split()] for _ in range(M)]
"""
price = []
for l in ml:
    price.append(al[l[0]-1] + bl[l[1]-1] - l[2])
for x in al:
    for y in bl:
        price.append(x+y)
"""
price = [al[l[0]-1] + bl[l[1]-1] - l[2] for l in ml] + [min(al)+min(bl)] 
print(min(price))