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:
def main():
    a, b, m = map(int, input().split())
    a_list = list(map(int, input().split()))
    b_list = list(map(int, input().split()))
    waribiki = []
    waribiki_result = 0

    for i in range(m):
        waribiki = list(map(int, input().split()))
        tmp_result = a_list[waribiki[0] - 1] + \
            b_list[waribiki[1] - 1] - waribiki[2]
        if i == 0:
            waribiki_result = tmp_result
        else:
            if tmp_result < waribiki_result:
                waribiki_result = tmp_result

    a_list.sort()
    b_list.sort()
    if a_list[0] + b_list[0] < waribiki_result:
        print(a_list[0] + b_list[0])
    else:
        print(waribiki_result)


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 = [list(map(int, input().split())) for _ 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()))
ans = min(a) + min(b)
for _ in range(M):
    xi, yi, ci = map(int, input().split())
    ans = min(ans, a[xi - 1] + b[yi - 1] - ci)
print(ans)

Submission status: Accepted

Solution code:
A, B, M = map(int, input().split(' '))
aa = list(map(int, input().split(' ')))
bb = list(map(int, input().split(' ')))
cc = []
for _ in range(M):
    x, y, c = map(int, input().split(' '))
    cc.append([x, y, c])

ans = min(aa) + min(bb)
for x, y, c in cc:
    price = aa[x - 1] + bb[y - 1] - c
    if price < ans:
        ans = price

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

Submission status: Accepted

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

Ae = list(map(int, input().split()))
Be = list(map(int, input().split()))

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

# Most cheap pair in normal
ans = min(Ae) + min(Be)

# Check each discount
for q in Queries:
    Ai = q[0] - 1
    Bi = q[1] - 1
    Disc = q[2]
    total = Ae[Ai] + Be[Bi] - Disc
    if total < ans:
        ans = total

print(ans)

Submission status: Accepted

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

def main():
    a, b, m = map(int, input().split())
    t_a = tuple(map(int, input().split()))
    t_b = tuple(map(int, input().split()))
    t_ken = [tuple(map(int, input().split())) for _ in range(m)]

    r = min(t_a) + min(t_b)
    for x, y, c in t_ken:
        r = min(r, t_a[x-1] + t_b[y-1] - c)
    print(r)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def getint():
    a = input().split()
    for i in range(len(a)):
        a[i] = int(a[i])
    return a

def main(fr,el,discount):
    return fr+el-discount

freeze,elec,disc = getint()
frprice = getint()
elecprice = getint()
price = []
elec_min = elecprice[0]
for i in range(elec):
    elec_min = min(elec_min,elecprice[i])
fr_min = frprice[0]
for i in range(freeze):
    fr_min = min(fr_min,frprice[i])
price.append(fr_min+elec_min)

for i in range(disc):
    x,y,c = getint()
    price.append(main(frprice[x-1],elecprice[y-1],c))
ans = price[0]
for i in range(len(price)):
    ans = min(ans,price[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()))
aa = sorted(a)
bb = sorted(b)
lis = []
mi = 10**12
for i in range(m):
  x, y, c = map(int, input().split())
  s = a[x-1]+b[y-1]-c
  mi = min(s, mi)
mii = aa[0]+bb[0]
ans = min(mii,mi)
print(ans)

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

a_min = min(a_list)
b_min = min(b_list)

sum_min = a_min + b_min

for _ in range(m):
  m_0, m_1, m_2 = list(map(int, input().split(" ")))
  a_m = a_list[m_0 - 1]
  b_m = b_list[m_1 - 1]
  if sum_min > (a_m + b_m - m_2):
    sum_min = a_m + b_m - m_2
print(sum_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()))
s = []
for i in range(m):
  x, y, c = map(int, input().split())
  s.append(A[x-1] + B[y-1] - c)
s.append(min(A) + min(B))
print(min(s))

Submission status: Accepted

Solution code:
a,b,m=map(int,input().split())
alis=list(map(int,input().split()))
blis=list(map(int,input().split()))
ans=10**18
d=dict()
for i in range(m):
  x,y,c=map(int,input().split())
  x-=1
  y-=1
  d[(x,y)]=c
  ans=min(ans,alis[x]+blis[y]-c)
alis1=[]
blis1=[]
for i in range(a):
  alis1.append((alis[i],i))
for i in range(b):
  blis1.append((blis[i],i))
alis1.sort()
blis1.sort()
if (alis1[0][1],blis1[0][1]) not in d:
  ans=min(ans,alis1[0][0]+blis1[0][0])
print(ans)

Submission status: Accepted

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

cost_a = list(map(int, input().split()))
cost_b = list(map(int, input().split()))

ans = min(cost_a) + min(cost_b)

for m in range(M):
    coupon = list(map(int, input().split()))
    ans = min(ans, cost_a[coupon[0]-1]+cost_b[coupon[1]-1]-coupon[2])

print(ans)

Submission status: Accepted

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

a_items = list(map(int, input().split()))
b_items = list(map(int, input().split()))


m = min(a_items) + min(b_items)
value = m

for _ in range(M):
    x, y, c = list(map(int, input().split()))
    z = a_items[x-1] + b_items[y-1] - c

    if value > z:
        value = z

print(value)

Submission status: Accepted

Solution code:
A, B, M = map(int, input().split())
*a, = map(int, input().split())
*b, = 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()))
x=[]
y=[]
c=[]
rei=[[]for i in range(A)]
for i in range(m):
    x1,y1,c1=map(int,input().split())
    x.append(x1-1)
    y.append(y1-1)
    c.append(c1)
    #rei[x1-1].append((y1-1,c1))
    rei[x1-1].append(b[y1-1]-c1)


saisho=min(a)+min(b)

for i in range(m):
    gen=a[x[i]]+b[y[i]]-c[i]
    if(gen<saisho):
        saisho=gen

print(saisho)

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(map(int,input().split())) for _ in range(m)]
ans = min(a) + min(b)

for i in range(m):
	ans = min(a[x[i][0]-1] + b[x[i][1]-1] - x[i][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()))

discount = []
for i in [0]*M:
    discount.append(list(map(int,input().split())))

min_comb = min(a)+min(b)

for i in range(M):
    min_comb = min(min_comb,a[discount[i][0]-1]+b[discount[i][1]-1]-discount[i][2])
ans = min_comb
print(ans)

Submission status: Accepted

Solution code:
a, b, m = input().split(" ")
rei_list = []
den_list = []
war_list = []
rei_list = list(map(int,input().split(" ")))
den_list = list(map(int,input().split(" ")))

for i in range(int(m)):
    kar = list(map(int,input().split(" ")))
    war_list.append(kar)

ned_list=[]
ned_list.append(min(rei_list)+min(den_list))

for i in range(int(m)):
    x = war_list[i][0]
    y = war_list[i][1]
    z = war_list[i][2]
    ned_list.append(rei_list[x-1] + den_list[y-1] - z)
    
print(min(ned_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()))

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

print(min(min(ans),(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 = []

ans = min(A) + min(B)
for i 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
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()))
minu = min(al) + min(bl)
for i in range(m):
    an, bn, wari = map(int, input().split())
    if minu > (al[an -1] + bl[bn -1] - wari):
        minu = (al[an -1] + bl[bn -1] - wari)
print(minu)

Submission status: Accepted

Solution code:
def main():
    A, B, M = map(int, input().split())
    xyc_list = [0]*M

    a_list = list(map(int, input().split()))
    b_list = list(map(int, input().split()))
    for i in range(M):
        xyc_list[i] = list(map(int, input().split()))

    mini = min(a_list)+min(a_list)
    for x, y, c in xyc_list:
        value = a_list[x-1] + b_list[y-1] - c
        if value < mini:
            mini = value
    print(mini)


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)
for _ in range(M):
  a, b, c = map(int, input().split())
  total = A[a-1]+B[b-1]-c
  ans = min(ans, total)
print(ans)

Submission status: Accepted

Solution code:
A, B, M = [int(num) for num in input().split()]
a = [int(num) for num in input().split()]
b =  [int(num) for num in input().split()]
minimum = -1
for i in range(M):
    xi, yi, ci =  [int(num) for num in input().split()]
    ai = a[xi-1]
    bi = b[yi-1]
    sum = ai + bi - ci
    if minimum == -1 or sum < minimum:
        minimum = sum
a.sort()
b.sort()
sum = a[0]+b[0]
if minimum < sum:
    print(minimum)
else:
    print(sum)

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())
    if(ans > a[X-1]+b[Y-1]-C):
        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)]

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

Submission status: Accepted

Solution code:
a, b, m = map(int, input().split())
As = list(map(int, input().split()))
Bs = list(map(int, input().split()))
k = []
notDisc = min(As) + min(Bs)
k.append(notDisc)
for i in range(m):
    t1,t2,t3 = map(int, input().split())
    dis = As[t1-1] + Bs[t2-1] - t3
    k.append(dis)
print(min(k))

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 i in range(M):
    m_list.append(list(map(int, input().split())))

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

print(ans)

Submission status: Accepted

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

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


mini = min(a_list) + min(b_list)
for i in range(m):
  ai = m_list[i][0] - 1
  bi = m_list[i][1] - 1
  ci = m_list[i][2]

  temp = a_list[ai] + b_list[bi] - ci

  if temp < mini:
    mini = temp
print(mini)

Submission status: Accepted

Solution code:
#input
#S = input()
#N = int(input())
Anum, Bnum, Mnum = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
M = []
for _ in range(Mnum):
    M.append(list(map(int, input().split())))
    
# process
ans = min(A)+min(B)
for x, y, c in M:
    cost = A[x-1]+B[y-1]-c
    if cost < ans:
        ans = cost

# output
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())
f = list(map(int, input().split()))
g = list(map(int, input().split()))
ans = min(f) + min(g)
for _ in range(m):
  x,y,c = map(int, input().split())
  t = f[x-1] + g[y-1] - c
  if ans > t: ans = t
print(ans)

Submission status: Accepted

Solution code:
a,b,m=map(int,input().split())
aa=list(map(int,input().split()))
bb=list(map(int,input().split()))
x=[ list(map(int,input().split())) for i in range(m)]
hantei=1000000000000
for i in range(m):
  if hantei>=(aa[x[i][0]-1]+bb[x[i][1]-1]-x[i][2]):
    hantei=(aa[x[i][0]-1]+bb[x[i][1]-1]-x[i][2])
if hantei>=min(aa)+min(bb):
  hantei=min(aa)+min(bb)
print(hantei)

Submission status: Accepted

Solution code:
a,b,m=map(int,input().split())
af=list(map(int,input().split()))
bf=list(map(int,input().split()))
almin=sorted(af)
blmin=sorted(bf)
nmin=almin[0]+blmin[0]
bmin=blmin[0]
for i in range(m):
  x,y,c=map(int,input().split())
  k=af[x-1]+bf[y-1]-c
  if k<nmin:
    nmin=k
print(nmin)

Submission status: Accepted

Solution code:
a, b, m = list(map(int, input().split()))
# 割引券
a_ary = list(map(int, input().split()))
b_ary = list(map(int, input().split()))
waribiki = []
for i in range(m):
    waribiki.append(list(map(int, input().split())))
# 普通に買った場合の最小
min_cost = min(a_ary) + min(b_ary)
# 割引券を使った場合の最小
for i in range(m):
    tmp = a_ary[waribiki[i][0]-1] + b_ary[waribiki[i][1]-1] - waribiki[i][2]
    if tmp < min_cost:
        min_cost = tmp
print(min_cost)

Submission status: Accepted

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

from collections import defaultdict

a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]

MINB = min(b)

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

ans = float("inf")
for i in range(A):
    tmp = a[i] + MINB
    for y,c in wari[i]:
        tmp = min(tmp, a[i] + b[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()))

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())
list_A = list(map(int, input().split()))
list_B = list(map(int, input().split()))
ans = min(list_A) + min(list_B)


for i in range(M):
    tmp_list = list(map(int, input().split()))
    tmp_cost = list_A[tmp_list[0]-1] + list_B[tmp_list[1]-1] - tmp_list[2]
    ans = min(tmp_cost, ans)

print(ans)

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

minnum = min(a_list) + min(b_list)

for i in range(m):
    x,y,c = list(map(int,input().split()))
    if minnum > a_list[x-1] + b_list[y-1] - c:
        minnum = a_list[x-1] + b_list[y-1] - c

print(minnum)

Submission status: Accepted

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

min_a = 10**5
for i in range(A):
    if min_a > a[i]:
        min_a = a[i]

min_b = 10**5
for i in range(B):
    if min_b > b[i]:
        min_b = b[i]

min = min_a + min_b
#print(min)

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

print(min)

Submission status: Accepted

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

tmp_min = min(a)+min(b)

for i in range(M):
    tmp = a[x[i][0]-1]+b[x[i][1]-1] - x[i][2]
    if tmp < tmp_min:
        tmp_min = tmp
    else:
        pass

print(tmp_min)

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(x) for x in input().split()]

x_list = []
y_list = []
c_list = []

for s in range(m):
  x,y,c = (int(value) for value in input().split())
  x_list.append(x)
  y_list.append(y)
  c_list.append(c)

min_value = min(a_list) + min(b_list)

for i in range(len(x_list)):
  value = a_list[x_list[i]-1] + b_list[y_list[i]-1] - c_list[i]
  if value < min_value:
    min_value = value
print(min_value)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
info = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
num = -1
for i in range(info[2]):
    temp = [int(i) for i in input().split()]
    price = a[temp[0]-1]+b[temp[1]-1]-temp[2]
    if (num == -1 or num > price):
        num = price
if min(a)+min(b) < num:
    num = min(a)+min(b)
print(num)

Submission status: Accepted

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

a, b, m = map(int, input().split())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
res = min(A) + min(B)
for j in range(m):
    x, y, c = map(int, input().split())
    summ = A[x-1] + B[y-1] - c
    if summ < res:
        res = summ

print(res)

Submission status: Accepted

Solution code:
a_len, b_len, m = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
ds = [[int(i) for i in input().split()] for _ in range(m)]

min = min(a) + min(b)
for x, y, c in ds:
    price = a[x-1] + b[y-1] - c
    if price < min:
        min = price

print(min)

Submission status: Accepted

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

As = [int(x) for x in input().rstrip().split()]
Bs = [int(x) for x in input().rstrip().split()]

min_val = min(As) + min(Bs)

for i in range(M):
    x, y, c = map(int, input().rstrip().split())
    val = As[x-1] + Bs[y-1] - c
    if min_val > val:
        min_val = val
print(min_val)

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 i in range(M):
  x = list(map(int, input().split()))
  m.append(x)
a_min = min(a)
b_min = min(b)
s_min = a_min + b_min
for i in range(M):
  if a[m[i][0]-1] + b[m[i][1]-1] - m[i][2] < s_min:
    s_min = a[m[i][0]-1] + b[m[i][1]-1] - m[i][2]
print(s_min)

Submission status: Accepted

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

m = []
for i in range(M):
    m.append([int(v) for v in input().split()])

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

for w in m:
    ai, bi, ci = w
    tmp_min = a[ai-1] + b[bi-1] - ci
    if tmp_min < s_min:
        s_min = tmp_min
        
print(s_min)

Submission status: Accepted

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

xyc = []
for i in range(M):
    xyci = map(int, raw_input().split())
    xyc.append(xyci)

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

ans = a_min + b_min

for i in range(M):
    xi = xyc[i][0]-1
    yi = xyc[i][1]-1
    ci = xyc[i][2]

    cost = a[xi]+ b[yi] -ci
    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()))
D = [list(map(int, input().split())) for _ in range(m)]

l = sorted(A)[0]+sorted(B)[0]
for d in D:
    l = min(l, A[d[0]-1]+B[d[1]-1]-d[2])
print(l)

Submission status: Accepted

Solution code:
A,B,M=[int(x) for x in input().rstrip().split()]
a=[int(x) for x in input().rstrip().split()]
b=[int(x) for x in input().rstrip().split()]
a_min=min(a)
b_min=min(b)

ans=a_min+b_min
for i in range(M):
    x,y,c=[int(x) for x in input().rstrip().split()]
    now=a[x-1]+b[y-1]-c
    if now<ans:
        ans=now
print(ans)

Submission status: Accepted

Solution code:
#
import sys
import math
import numpy as np
import itertools

# いくつか入力
a, b, m = (int(i) for i in input().split())  

aprice = [int(i) for i in input().split()] 
bprice = [int(i) for i in input().split()] 
c = [[int(i) for i in input().split()] for i in range(m)] 
#print(aprice,bprice,c)
amin=999999
for i in range(a):
    amin = min(amin,aprice[i])
bmin=999999
for i in range(b):
    bmin = min(bmin,bprice[i])

p=[]
for i in range(m):
#    print(c[i][0],c[i][1],c[i][2])
    p.append(aprice[c[i][0]-1]+bprice[c[i][1]-1]-c[i][2])

answer = amin+bmin
for i in p:
    answer = min(answer, i) 

print(answer)

Submission status: Accepted

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

a_m=min(a)
b_m=min(b)

ans=(a_m+b_m)
tem=0

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


print(ans)

Submission status: Accepted

Solution code:
a, b, m = map(int, input().split())
arr1 = [int(j) for j in input().split()]
arr2 = [int(j) for j in input().split()]

pfx1 = []
pfx2 = []

su = 0
for i in range(a):
	su += arr1[i]
	pfx1 += [su]
su = 0
for i in range(b):
	su += arr2[i]
	pfx2 += [su]

mi = 9999999999999
k1 = min(arr1)
k2 = min(arr2)
for i in range(m):
	x, y, c = map(int, input().split())
	mi = min(mi, arr1[x-1]+arr2[y-1]-c, k1+k2)
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()))
m = [list(map(int, input().split())) for _ in range(M)]

#solve
cheapest = min(a) + min(b)
for i in m:
  price = a[i[0]-1] + b[i[1]-1] - i[2]
  if price < cheapest: cheapest = price
print(cheapest)

Submission status: Accepted

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

list_x = [0] * M
list_y = [0] * M
list_c = [0] * M

for i in range(M):
    list_x[i], list_y[i], list_c[i] = \
        [int(x) for x in input().split()]




min_ab = min(list_a) + min(list_b)

for i in range(M):
    min_ab = min(min_ab, list_a[list_x[i]-1] + list_b[list_y[i]-1] - list_c[i])

print(min_ab)

Submission status: Accepted

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

min_cost = min(a) + min(b)

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

print(min_cost)

Submission status: Accepted

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

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

for i in range(M):
    price = a[MList[i][0]-1] + b[MList[i][1]-1] - MList[i][2]
    if (ans > price):
        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())) 
c = [list(map(int, input().split())) for i in range(M)]
price = [a[int(c[i][0])-1] + b[int(c[i][1]-1)] - int(c[i][2]) for i in range(M)]
saiyasu = min(a) + min(b)
print(min(min(price),saiyasu))

Submission status: Accepted

Solution code:
def main(A,B,p):
    mina = min(A)
    minb = min(B)
    res = mina + minb
    for i in range(len(p)):
        x = A[p[i][0]-1]
        y = B[p[i][1]-1]
        val = x+y-p[i][2]
        if val < res:
            res = val
    return res

a,b,m = map(int,input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
p = [list(map(int, input().split())) for _ in range(m)]
print(main(A,B,p))

Submission status: Accepted

Solution code:
[A, B, M]    = list(map(int, input().split()))
lst_a        = list(map(int, input().split()))
lst_b        = list(map(int, input().split()))
lst_discount = [list(map(int, input().split())) for i in range(M)]

def main(lst_a, lst_b, lst_discount):

    lst_price = [min(lst_a) + min(lst_b)]

    for discount in lst_discount:
        reizouko = lst_a[discount[0] - 1]
        renji    = lst_b[discount[1] - 1]
        lst_price.append(reizouko + renji - discount[2])
    
    return min(lst_price)


if __name__ == "__main__":

    answer = main(lst_a, lst_b, lst_discount)
    print(answer)

Submission status: Accepted

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

#処理
x=min(a)+min(b)

for i in d:
    t=a[i[0]-1]+b[i[1]-1]-i[2]
    if t<x:
        x=t
print(x)

Submission status: Accepted

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip()

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

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

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

disc.sort()
min_ab = min(a) + min(b)

if disc[0] <= min_ab:
    print(disc[0])
else:
    print(min_ab)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
A, B, M = [int(i) for i in input().split(' ')]
A_list = [int(i) for i in input().split(' ')]
B_list = [int(i) for i in input().split(' ')]

min_val = min(A_list) + min(B_list)
for k in range(M):
    x,y,c = [int(i) for i in input().split(' ')]
    tmp = A_list[x-1] + B_list[y-1] - c
    if tmp < min_val:
        min_val = tmp
if min_val < tmp:
    print(min_val)
else:
    print(tmp)

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

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

Submission status: Accepted

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

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)]
xyc.sort(key=lambda x:(x[0], x[1], x[2]))
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:
from sys import stdin
import math

a, b, m = [int(x) for x in stdin.readline().rstrip().split()]
aa = [int(x) for x in stdin.readline().rstrip().split()]
bb = [int(x) for x in stdin.readline().rstrip().split()]

result = min(aa) + min(bb)

for i in range(m):
    x, y, c = [int(x) for x in stdin.readline().rstrip().split()]
    temp = aa[x-1] + bb[y-1] - c
    if temp < result:
        result = temp

print(result)

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

mincost = 10**12
for _ in range(M):
	x, y, c = [int(i) for i in input().split()]
	cost = a[x-1] + b[y-1] - c
	if cost < mincost:
		mincost = cost
nodiscount_cost = min(a) + min(b)
if nodiscount_cost < mincost:
	print(nodiscount_cost)
else:
	print(mincost)

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

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