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: Runtime Error

Solution code:
import sys
import numpy as np

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

prices_A=np.array(list(map(int,input().split())),dtype='int16')
prices_B=np.array(list(map(int,input().split())),dtype='int16')

dc=np.zeros((M,B),dtype='int16')

for n in range(M):
    (x,y,c)=map(int,input().split())
    i=x-1
    j=y-1
    dc[n,j]=c

#print(prices_A)
#print(prices_B)
#print(dc)

min_p = prices_A[0] + prices_B[0]
for i in range(A):
    for n in range(M):
        dcB=prices_B-dc[n]

    p=prices_A[i]+dcB.min()
    if p < min_p:
        min_p=p
print(min_p)

Submission status: Runtime Error

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

disc = [list(map(int, input().split())) for i in range(m)]
import numpy as np

b2 = np.array(b1)
a2 = np.array(a1)
a2 = a2.reshape(a,1)

from collections import deque
ans = []
ans = deque(ans)

for i in range(m):
    ans.append( a1[disc[i][0]-1] + b1[disc[i][1]-1] - disc[i][2] )

ans = list(ans)
print(min( min(ans), np.min(a2+b2) ))

Submission status: Runtime Error

Solution code:
A, B, M = map(int, input().split())
aryAPrice = list(map(int, input().strip().split()))
aryBPrice = list(map(int, input().strip().split()))
aryDiscount = [[0]*3]*M
for i in range(M):
    aryDiscount[i] = list(map(int, input().strip().split()))

intABest = aryAPrice[0]
intBBest = aryBPrice[0]
for i in aryAPrice:
    if intABest > i:
        intABest = i

for i in aryBPrice:
    if intBBest > i:
        intBBest = i

bestSum = intABest + intBBest

for i in aryDiscount:
    hikaku = aryAPrice[i[0]] + aryBPrice[i[1]] - i[2]
    if bestSum > hikaku:
        bestSum = hikaku:

print(bestSum)

Submission status: Runtime Error

Solution code:
import numpy as np


A, B, M = map(int, input().split())
a = list(map(int, input().split()))
a = np.array(a)
b = list(map(int, input().split()))
b = np.array(b)
z = [list(map(int, input().split())) for _ in range(M)]
z = np.array(z)


xx, yy = np.meshgrid(a, b)
xx1 = xx.flatten()
yy1 = yy.flatten()

xxyy = np.c_[xx1, yy1]
mem = xxyy.sum(axis=1)
mem = list(mem)

for x, y, c in z:
    mem.append(a[x - 1] + b[y - 1] - c)
   

print(min(mem))

Submission status: Runtime Error

Solution code:
import numpy as np


A, B, M = map(int, input().split())
a = list(map(int, input().split()))
a = np.array(a)
b = list(map(int, input().split()))
b = np.array(b)
z = [list(map(int, input().split())) for _ in range(M)]
z = np.array(z)


# for i in range(len(a)):
#     for j in range(len(b)):
#         mem.append(a[i] + b[j])

xx, yy = np.meshgrid(a, b)
xx1 = xx.flatten()
yy1 = yy.flatten()

xxyy = np.c_[xx1, yy1]
mem = xxyy.sum(axis=1)
mem = list(mem)

for x, y, c in z:
    mem.append(a[x - 1] + b[y - 1] - c)
    # np.append(mem, (a[x - 1] + b[y - 1] - c))

print(min(mem))
# print(mem)

Submission status: Runtime Error

Solution code:
import sys
import numpy as np

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

prices_A=np.array(list(map(int,input().split())),dtype='int16')
prices_B=np.array(list(map(int,input().split())),dtype='int16')

dc=np.zeros((A,B),dtype='int16')

for n in range(M):
    (x,y,c)=map(int,input().split())
    i=x-1
    j=y-1
    dc[i,j]=c

#print(prices_A)
#print(prices_B)
#print(dc)

min_p = prices_A[0] + prices_B[0]
for i in range(A):
    dcB=prices_B-dc[i]

    p=prices_A[i]+dcB.min()
    if p < min_p:
        min_p=p
print(min_p)

Submission status: Runtime Error

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

min = 99999999

calced = []

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

k = 0

for i in range(A):
    for j in range(B):
        if calced[k][0] == i & calced[k][1] == j:
            k = k + 1
            continue;
        cost = a[i] + b[j]
        if cost < min:
            min = cost

print(min)

Submission status: Runtime Error

Solution code:
import sys
import numpy as np

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

prices_A=np.array(list(map(int,input().split())),dtype='int32')
prices_B=np.array(list(map(int,input().split())),dtype='int32')

dc=np.zeros((A,B),dtype='int32')

for n in range(M):
    (x,y,c)=map(int,input().split())
    i=x-1
    j=y-1
    dc[i,j]=c

#print(prices_A)
#print(prices_B)
#print(dc)

min_p = prices_A[0] + prices_B[0]
for i in range(A):
    dcB=prices_B-dc[i]

    p=prices_A[i]+dcB.min()
    if p < min_p:
        min_p=p
print(min_p)

Submission status: Runtime Error

Solution code:
import sys
import numpy as np

# input = sys.stdin.readline

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

microwave = list(map(int, input().split()))

refrigerator = list(map(int, input().split()))

dis_nm = np.zeros((a+1, b+1), dtype=np.int32)
for ii in range(m):
    an, bn, mn = map(int, input().split())
    if dis_nm[an, bn] < mn:
        dis_nm[an, bn] = mn
money = 99999999999
for i, ai in enumerate(microwave, start=1):
    for j, bi in enumerate(refrigerator, start=1):
        mi = ai + bi - dis_nm[i, j]
#         key_ij = str(i).zfill(5) + str(j).zfill(5)
#         dis_max = dis_dict.get(key_ij, 0)
#         for dis in Discount:
#             if (dis[0] == i+1) and (dis[1] == j+1):
#                 if dis[2] > dis_max:
#                     dis_max = dis[2]
#         mi -= dis_max
        if money > mi:
            money = mi
print(int(money))

Submission status: Runtime Error

Solution code:
import numpy as np
a,b,m = [int(i) for i in input().split()]
aa = [int(i) for i in input().split()]
bb = [int(i) for i in input().split()]
x = np.zeros(m,dtype=int)
y = np.zeros(m,dtype=int)
c = np.zeros(m,dtype=int)
for i in range(m):
    x[i],y[i],c[i] = [int(j) for j in input().split()]
r = np.zeros((a,b),dtype=int)
for i in range(a):
    for j in range(b):
        r[i][j] = aa[i] + bb[j]
v = np.min(r)
# for i,j,l in zip(x,y,c):
#     if v > (r[i-1][j-1] - l):
#         v = r[i-1][j-1] - l
print(v)

Submission status: Runtime Error

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

a = np.array(a)
b = np.array(b)

dp = np.zeros((A+1,B+1),dtype='int')
for i in range(M):
    x,y,c = map(int,input().split())
    dp[x,y] = min(dp[x,y],-c) 



for j in range(1,A+1):
    for k in range(1,B+1):
        dp[j,k] += a[j-1] + b[k-1]

dp = np.delete(dp,0,0)
dp = np.delete(dp,0,1)

print(dp.min())

Submission status: Runtime Error

Solution code:
a,b,m=map(int, input().split())
rei=list(map(int, input().split())) 
den=list(map(int, input().split())) 
cou = [0] * m
ans = 100000
for i in range(m):
	cou[i]=list(map(int, input().split()))
	c=rei[cou[i][0]-1]+den[cou[i][1]-1]-cou[i][2]
	if ans>c:
		ans=c
c=min(a)+min(b)
if ans>c:
		ans=c
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
a,b,m = [int(i) for i in input().split()]
aa = [int(i) for i in input().split()]
bb = [int(i) for i in input().split()]
x = np.zeros(m,dtype=int)
y = np.zeros(m,dtype=int)
c = np.zeros(m,dtype=int)
for i in range(m):
    x[i],y[i],c[i] = [int(j) for j in input().split()]
r = np.zeros((a,b),dtype=int)
for i in range(a):
    for j in range(b):
        r[i][j] = aa[i] + bb[j]
v = np.min(r)
for i,j,l in zip(x,y,c):
    if v > r[i-1][j-1] - l:
        v = r[i-1][j-1] - l
print(v)

Submission status: Runtime Error

Solution code:
import itertools

if __name__ == "__main__":
    A, B, M = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    xyc = []
    pc_max = 0
    for i in range(M):
        x, y, c = map(int, input().split())
        if c > pc_max:
            xyc = [x, y, c]
        elif c == pc_max:
            xyc.append([x, y, c])
        else:
            continue
    # print(A)
    # print(B)
    # print(xyc)

    p_min = min(A) + min(B)
    for j in xyc:
        if j is int:
            if p_min >= (A[xyc[0]-1] + B[xyc[1]-1] - xyc[2]):
                p_min = A[xyc[0]-1] + B[xyc[1]-1] - xyc[2]
                break
            else:
                break
        elif p_min >= (A[j[0]-1] + B[j[1]-1] - j[2]):
            p_min = A[j[0]-1] + B[j[1]-1] - j[2]
        else:
            continue
    print(p_min)

Submission status: Runtime Error

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

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

print(result)

Submission status: Runtime Error

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

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

x = []
y = []
c = []
for i in range(M):
    [inx, iny, inc] = list(map(int, input().split()))
    x.append(inx)
    y.append(iny)
    c.append(inc)

cut_map = [[0*i for i in range(B)] for j in range(A)]
for i in range(M):
    if cut_map[x[i]-1][y[i]-1] > -c[i]:
        cut_map[x[i]-1][y[i]-1] = -c[i]

cost_map = [[0*i for i in range(B)] for j in range(A)]

for i in range(A):
    for j in range(B):
        cost_map[i][j] = a[i] + b[j] + cut_map[i][j]


import numpy as np
ex1 = np.array(cost_map)
print(np.min(ex1))

Submission status: Runtime Error

Solution code:
import sys
import numpy as np

# input = sys.stdin.readline

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

microwave = list(map(int, input().split()))

refrigerator = list(map(int, input().split()))

dis_nm = np.zeros((a+1, b+1))
for ii in range(m):
    an, bn, mn = map(int, input().split())
    if dis_nm[an, bn] < mn:
        dis_nm[an, bn] = mn
money = 99999999999
for i, ai in enumerate(microwave, start=1):
    for j, bi in enumerate(refrigerator, start=1):
        mi = ai + bi - dis_nm[i, j]
#         key_ij = str(i).zfill(5) + str(j).zfill(5)
#         dis_max = dis_dict.get(key_ij, 0)
#         for dis in Discount:
#             if (dis[0] == i+1) and (dis[1] == j+1):
#                 if dis[2] > dis_max:
#                     dis_max = dis[2]
#         mi -= dis_max
        if money > mi:
            money = mi
print(int(money))

Submission status: Runtime Error

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

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

x = []
y = []
c = []
for i in range(M):
    [inx, iny, inc] = list(map(int, input().split()))
    x.append(inx)
    y.append(iny)
    c.append(inc)

cut_map = [[0*i for i in range(B)] for j in range(A)]
for i in range(M):
    if cut_map[x[i]-1][y[i]-1] > -c[i]:
        cut_map[x[i]-1][y[i]-1] = -c[i]

cost_map = [[0*i for i in range(B)] for j in range(A)]

for i in range(A):
    for j in range(B):
        cost_map[i][j] = a[i] + b[j] + cut_map[x[i]-1][y[i]-1]


import numpy as np
ex1 = np.array(cost_map)
print(np.min(ex1))

Submission status: Runtime Error

Solution code:
import sys
import numpy as np

input = sys.stdin.readline

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

microwave = list(map(int, input().split()))

refrigerator = list(map(int, input().split()))

dis_nm = np.zeros((a+1, b+1))
for ii in range(m):
    an, bn, mn = map(int, input().split())
    if dis_nm[an, bn] < mn:
        dis_nm[an, bn] = mn
money = 99999999999
for i, ai in enumerate(microwave, start=1):
    for j, bi in enumerate(refrigerator, start=1):
        mi = ai + bi - dis_nm[i, j]
#         key_ij = str(i).zfill(5) + str(j).zfill(5)
#         dis_max = dis_dict.get(key_ij, 0)
#         for dis in Discount:
#             if (dis[0] == i+1) and (dis[1] == j+1):
#                 if dis[2] > dis_max:
#                     dis_max = dis[2]
#         mi -= dis_max
        if money > mi:
            money = mi
print(int(money))

Submission status: Runtime Error

Solution code:


a,b,m = [int(x) for x in input().split()]
an = [(int(x),i+1) for i,x in enumerate(input().split())]
bn = [(int(x),i+1) for i,x in enumerate(input().split())]

an = sorted(an)
bn = sorted(bn)

discounts = {}
discount_list = []
for i in range(m):
    x,y,c = [int(x) for x in input().split()]
    if (x,y) in discounts and discounts[(x,y)] > c:
        continue
    discounts[(x,y)] = c
    discount_list.append(c)

discount_list = sorted(discount_list,reverse=True)

i = 0
j = 0
min = an[0][0]+bn[0][0]
max_discount = max(discount_list)
len_an = len(an)
len_bn = len(bn)

# print(an)
# print(bn)
# print(min)
# print(discounts)

while True:
    a_index = an[i][1]
    b_index = bn[j][1]
    discount = 0
    if (a_index, b_index) in discounts:
        discount = discounts[(a_index, b_index)]
    total = an[i][0] + bn[j][0] - discount
    if min > total:
        min = total

    if an[i][0] + bn[j][0] - max_discount > min:
        break
    elif i == len_an-1 and j == len_bn-1:
        break
    elif i == len_an-1:
        j += 1
    elif j == len_bn-1:
        i += 1
    else:
        a_diff = an[i+1][0] - an[i][0]
        b_diff = bn[j+1][0] - an[j][0]
        if a_diff < b_diff:
            i += 1
        else:
            j += 1


print(min)

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10**9)

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

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

import itertools
import numpy as np

b2 = np.array(b1)
b2 = np.tile(b2, (a,1))

ans = []
from collections import deque
ans = deque(ans)

for i in range(a):
    ans.append( np.min( b2[i] + np.tile(a1[i], b) ) )


for i in range(m):
    ans.append( a1[disc[i][0]-1] + b1[disc[i][1]-1] - disc[i][2] )

ans = list(ans)
print(min(ans))

Submission status: Runtime Error

Solution code:
import numpy as np
a,b,m = [int(i) for i in input().split()]
aa = [int(i) for i in input().split()]
bb = [int(i) for i in input().split()]
x = np.zeros(m,dtype=int)
y = np.zeros(m,dtype=int)
c = np.zeros(m,dtype=int)
for i in range(m):
    x[i],y[i],c[i] = [int(j) for j in input().split()]
r = np.zeros((a,b),dtype=int)
for i in range(a):
    for j in range(b):
        r[i][j] = aa[i] + bb[j]
v = np.min(r)
for i in range(m):
    if v > r[x[i]-1][y[i]-1] - c[i]:
        v = r[x[i]-1][y[i]-1] - c[i]
print(v)

Submission status: Runtime Error

Solution code:
x = input();
y = x.split()
a = int(y[0])
b = int(y[1])
c = int(y[2])

z = input()
ref = z.split()

t = input()
mic = z.split()


mini = 1000000000

for i in range(c):
    f = input()
    q = f.split()
    indexref = int(q[0]) - 1
    indexmic = int(q[1]) - 1
    redux = int(q[2])
    price = int(ref[indexref]) + int(mic[indexmic]) - redux
    if(price < mini):
        mini = price
h = min(ref)
j = min(mic)

if(int(h) + int(j) < mini):
    mini = int(h) + int(j)


print(mini)

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10**11)

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

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

import itertools
import numpy as np

b2 = np.array(b1)
b2 = np.tile(b2, (a,1))

ans = []
from collections import deque
ans = deque(ans)

for i in range(a):
    ans.append( np.min( b2[i] + np.tile(a1[i], b) ) )


for i in range(m):
    ans.append( a1[disc[i][0]-1] + b1[disc[i][1]-1] - disc[i][2] )

ans = list(ans)
print(min(ans))

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
x = input();
y = x.split()
a = int(y[0])
b = int(y[1])
c = int(y[2])

z = input()
ref = z.split()

t = input()
mic = z.split()


mini = 1000000000

for i in range(c):
    f = input()
    q = f.split()
    indexref = int(q[0]) - 1
    indexmic = int(q[1]) - 1
    redux = int(q[2])
    price = int(ref[indexref]) + int(mic[indexmic]) - redux
    if(price < mini):
        mini = price


print(mini)

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10**6)

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

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

import itertools
import numpy as np

b2 = np.array(b1)
b2 = np.tile(b2, (a,1))

ans = []
from collections import deque
ans = deque(ans)

for i in range(a):
    ans.append( np.min( b2[i] + np.tile(a1[i], b) ) )


for i in range(m):
    ans.append( a1[disc[i][0]-1] + b1[disc[i][1]-1] - disc[i][2] )

ans = list(ans)
print(min(ans))

Submission status: Runtime Error

Solution code:
import numpy as np
a,b,m = [int(i) for i in input().split()]
aa = [int(i) for i in input().split()]
bb = [int(i) for i in input().split()]
x = np.zeros(m,dtype=int)
y = np.zeros(m,dtype=int)
c = np.zeros(m,dtype=int)
for i in range(m):
    x[i],y[i],c[i] = [int(j) for j in input().split()]
r = np.zeros((a,b),dtype=int)
for i in range(a):
    for j in range(b):
        r[i][j] = aa[i] + bb[j]
v = np.min(r)
for i in range(m):
    v = min(v,r[x[i]-1][y[i]-1] - c[i])
print(v)

Submission status: Runtime Error

Solution code:
x = input();
y = x.split()
a = int(y[0])
b = int(y[1])
c = int(y[2])

z = input()
ref = z.split()

t = input()
mic = z.split()

mini = 1000000000

for i in range(c):
    f = input()
    q = f.split()
    indexref = int(q[0]) - 1
    indexmic = int(q[1]) - 1
    redux = int(q[2])
    price = int(ref[indexref]) + int(mic[indexmic]) - 1
    if(price < mini):
        mini = price


print(mini)

Submission status: Runtime Error

Solution code:
import numpy as np
a,b,m = [int(i) for i in input().split()]
aa = [int(i) for i in input().split()]
bb = [int(i) for i in input().split()]
x = np.zeros(m,dtype=int)
y = np.zeros(m,dtype=int)
c = np.zeros(m,dtype=int)
for i in range(m):
    x[i],y[i],c[i] = [int(j) for j in input().split()]
r = np.zeros((a,b),dtype=int)
for i in range(a):
    for j in range(b):
        r[i][j] = aa[i] + bb[j]
v = np.min(r)
print(v)
for i in range(m):
    v = min(v,r[x[i]-1][y[i]-1] - c[i])
print(v)

Submission status: Runtime Error

Solution code:
a, b, m = input().split()
a, b, m = int(a), int(b), int(m)
a_values = input().split()
b_values = input().split()
m_values = {}
for i in range(m):
    m_values[i] = input().split()

min = int(a_values[int(m_values[0][0])-1]) + int(b_values[int(m_values[0][1])-1]) - int(m_values[0][2])
for i in range(1, m):
    now = int(a_values[int(m_values[i][0])-1]) + int(b_values[int(m_values[i][1])-1]) - int(m_values[i][2])
    if min > now:
        min = now
now = int(min(a_values)) + int(min(b_values))
if min > now:
  print(now)
else:
  print(min)

Submission status: Runtime Error

Solution code:
A, B, M = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
minimum = a[0]+b[0]

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

#a.sort()
#b.sort()

for i in a:
    #if i + b[0] > minimum:
        #break
    for j in b:
        tmp = i + j
        if minimum > tmp:
            minimum = tmp
        else:
            break

print(minimum)

Submission status: Runtime Error

Solution code:

[A, B, M] = input().split()
A = int(A)
B = int(B)
M = int(M)

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

x = []
y = []
c = []
for i in range(M):
    [inx, iny, inc] = list(map(int, input().split()))
    x.append(inx)
    y.append(iny)
    c.append(inc)

cost_map = [[0*i for i in range(B)] for j in range(A)]

for i in range(A):
    for j in range(B):
        cost_map[i][j] = a[i] + b[j]

for i in range(M):
    cost_map[x[i]][y[i]] = cost_map[x[i]][y[i]] - c[i]

import numpy as np
ex1 = np.array(cost_map)
print(np.min(ex1))

Submission status: Runtime Error

Solution code:
p = []
list1 = input()
a = input()
b = input()
list_1 = list(map(int, list1.split(" ")))
alist = list(map(int, a.split(" ")))
blist = list(map(int, b.split(" ")))
A = list_1[0]
B = list_1[1]
M = list_1[2]

for d in range(M):
  l = input()
  xyc = list(map(int, l.split(" ")))
  x = xyc[0]-1
  y = xyc[1]-1
  c = xyc[2]
  for i in range(A):
    for j in range(B):
      if x == i and y == j:
        p.append(alist[i]+blist[j]-c)
    	p.append(alist[i]+blist[j])
print(min(p))

Submission status: Runtime Error

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

mini = min(a) + min(b)

total = []
for i in s:
    total.append(a[int(i[0])-1]+b[int(i[1])]- int(i[-1]))
    
mini_2 = min(total)

if mini <= mini_2:
    print(mini)
else:
    print(mini_2)

Submission status: Runtime Error

Solution code:
p = []
list1 = input()
a = input()
b = input()
list_1 = list(map(int, list1.split(" ")))
alist = list(map(int, a.split(" ")))
blist = list(map(int, b.split(" ")))
A = list_1[0]
B = list_1[1]
M = list_1[2]

for i in range(M):
  l = input()
  xyc = list(map(int, l.split(" ")))
  x = xyc[0]-1
  y = xyc[1]-1
  c = xyc[2]
  for i in range(A):
    for j in range(B):
      if x == i and y == j:
        p.append(alist[i]+blist[j]-c)
    	p.append(alist[i]+blist[j])
print(min(p))

Submission status: Runtime Error

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

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

x = []
y = []
c = []
for i in range(M):
    [inx, iny, inc] = list(map(int, input().split()))
    x.append(inx)
    y.append(iny)
    c.append(inc)

cost_map = [[0*i for i in range(B)] for j in range(A)]

for i in range(A):
    for j in range(B):
        cost_map[i][j] = a[i] + b[j]

for i in range(M):
    cost_map[x[i],y[i]] = cost_map[x[i], y[i]] - c[i]

import numpy as np
ex1 = np.array(cost_map)
print(np.min(ex1))

Submission status: Runtime Error

Solution code:
A,B,M=map(int,input().split())
vecA=list(map(int,input().split()))
vecB=list(map(int,input().split()))
matX=[input().split() for k in range(M)]
price = 10**6
for i in range(0,M):
    pricecom = int(vecA[int(matX[i][0]) -1]) + int(vecB[int(matX[i][1]) -1]) - int(matX[i][2])
    if pricecom<= price:
        price=pricecom
    else:
        pass
for m in range(M):
    for n in range (M):
        price2=int(vecA[m]) + int(vecB[n])
        if price2<=price:
            price=price2
print(price)

Submission status: Runtime Error

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

mx=A[0]+B[0]-c[0][0]
for i in range(a):
    for j in range(b):
        if mx > A[i]+B[j]-c[j][i]:
            mx = A[i]+B[j]-c[j][i]
#print(A)
#print(B)
#rint(c)
print(mx)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
A,B,M = list(map(int,input().split()))

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

mini = min(a)+ min(b)

def check(Mlist, mini):
    if mini > a[Mlist[0]-1]+b[Mlist[1]-1]-Mlist[2]:
        return a[Mlist[0]-1]+b[Mlist[1]-1]-Mlist[2]
for i in range(M):
    mini = check(list(map(int,input().split())),mini)

print(mini)

Submission status: Runtime Error

Solution code:
import numpy as np
a,b,m = [int(i) for i in input().split()]
aa = [int(i) for i in input().split()]
bb = [int(i) for i in input().split()]
x = np.zeros(m,dtype=int)
y = np.zeros(m,dtype=int)
c = np.zeros(m,dtype=int)
for i in range(m):
    x[i],y[i],c[i] = [int(j) for j in input().split()]
r = np.zeros((a,b),dtype=int)
for i in range(a):
    for j in range(b):
        r[i][j] = aa[i] + bb[j]
for i in range(m):
    r[x[i]][y[i]] -= c[i]
print(np.min(r))

Submission status: Runtime Error

Solution code:
def main():
    a, b, m = map(int, input().split())
    priceOfMicrowaves = list(map(int, input().split()))
    priceOfRefrigerators = list(map(int, input().split()))
    priceTable = [list(map(int,input().split())) for i in range(m)]
    cheepest = priceOfMicrowaves[0] + priceOfRefrigerators[0]
    for p in priceOfMicrowaves:
        if cheepest == 0:
            break
        if p >= cheepest:
            continue
        for q in priceOfRefrigerators:
            if q >= cheepest:
                continue
            if p + q < cheepest:
                cheepest = p + q
    for price in priceTable:
        if cheepest == 0:
            break
        if priceOfMicrowaves[price[0]-1] >= cheepest:
            continue
        elif priceOfMicrowaves[price[1]-1] >= cheepest:
            continue
        elif priceOfMicrowaves[price[0]-1]+priceOfRefrigerators[price[1]-1]-price[2] < cheepest:
            cheepest = priceOfMicrowaves[price[0]-1]+priceOfRefrigerators[price[1]-1]-price[2]
    print(cheepest)
    
main()

Submission status: Runtime Error

Solution code:
import numpy as np
a,b,m = [int(i) for i in input().split()]
aa = [int(i) for i in input().split()]
bb = [int(i) for i in input().split()]
x = np.zeros(m)
y = np.zeros(m)
c = np.zeros(m)
for i in range(m):
    x[i],y[i],c[i] = [int(j) for j in input().split()]
r = np.zeros((a,b))
for i in range(a):
    for j in range(b):
        r[i][j] = aa[i] + bb[j]
for i in range(m):
    r[x[i]][[y[i]] -= c[i]
print(np.min(r))

Submission status: Runtime Error

Solution code:
import sys

def load(vtype=int):
    return vtype(input().strip())


def load_list(seplator=" ", vtype=int):
    return [vtype(v) for v in input().strip().split(seplator)]

A, B, M = tuple(load_list())

a = load_list()
b = load_list()

coupon = dict()
for _ in range(0, M):
    x, y, c = tuple(load_list())
    if (x-1, y-1) in coupon:
        coupon[(x-1,y-1)] = max(coupon[(x-1,y-1)], c)
    else:        
        coupon[(x-1,y-1)] = c 

minv = min(a) + min(b)

for i, j in coupon.keys():
    minv = min(minv, a[i] + b[i] - coupon[(i, j)])

print(minv)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
A,B,M = list(map(int,input().split()))

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

mini = min(a)+ min(b)

def check(Mlist, mini):
    if mini > a[Mlist[0]]+b[Mlist[1]]-Mlist[2]:
        return a[Mlist[0]]+b[Mlist[1]]-Mlist[2]
for i in range(M):
    mini = check(list(map(int,input().split())),mini)

print(mini)

Submission status: Runtime Error

Solution code:
A, B, M = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
minimum = a[0]+b[0]

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

a.sort()
b.sort()

for i in a:
    if i + b[0] > minimum:
        break
    for j in b:
        tmp = i + j
        if minimum > tmp:
            minimum = tmp
        else:
            break

print(minimum)

Submission status: Runtime Error

Solution code:
data = input().split(" ")
A = input().split(" ")
B = input().split(" ")
total = 0
a = 0
b = 0
j = 0
for i in data:
    data[j] = int(i)
    j += 1
j = 0
for i in A:
    A[j] = int(i)
    j += 1
j = 0
for i in B:
    B[j] = int(i)
    j += 1


for i in range(data[2]):
    data1 = input().split()
    j = 0
    for i in data1:
        data1[j] = int(i)
        j += 1
    data2 = A[data1[0]] + B[data[1]] - data1[2]
    if total > data2:
        total = data2

for i in A:
    if a > i:
        a = i
for i in B:
    if b > i:
        b = i

if total > a+b:
    total = a+b

print(total)

Submission status: Runtime Error

Solution code:
i=list(map(int, input().split()))
a=list(map(int, input().split()))
b=list(map(int, input().split()))
A=i[0]
B=i[1]
M=i[2]
x = []
y = []
c = []
for j in range(M):
    x1,y1,c1=[int(j) for j in input().split()]
    x.append(x1)
    y.append(y1)
    c.append(c1)
d=200001
e=100001
f=100001
for k in range (A):
    if a[k]<e:
        e=a[k]

for l in range (B):
    if b[k]<f:
        f=b[k]
d=e+f

for p in range (M):
    if a[x[p]-1]+b[y[p]-1]-c[p]<d:
        d= a[x[p]-1]+b[y[p]-1]-c[p]

print(d)

Submission status: Runtime Error

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

list = []

for i in range(M):
  if min(a) + min(b) > a[d[i][0] - 1] + b[d[i][1] - 1] - d[i][2]:
    list.append(a[d[i][0] - 1] + b[d[i][1] - 1] - d[i][2])

print(min(list))

Submission status: Runtime Error

Solution code:
A, B, M = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
minimum = a[0]+b[0]

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

a.sort()
b.sort()

#tmpind = b[0]
for i in a:
#    if i + tmpind > minimum:
#        break
    for ind, j in enumerate(b):
        tmp = i + j
        if minimum > tmp:
            minimum = tmp
        else:
#            tmpind = ind
            break

print(minimum)

Submission status: Runtime Error

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
z = [0]*M
for i in range(M):
  x[i],y[i],z[i] = map(int,input().split())
zsort = sorted(z)
ma = max(zsort)
ind = z.index(ma)
am = min(a)
bm = min(b)
mae = am + bm
indxy = a[ind-1] + b[ind-1] - ma


if mae < indxy:
  print(mae)
else:
  print(indxy)

Submission status: Runtime Error

Solution code:
R = lambda: tuple(map(int, input().split()))
A, B, M = R()
a, b = R(), R()
d = (R() for _ in range(M))
print(min([min(a) + min(b)] + [a[x - 1] + b[x - 1] - c for x, y, c in d]))

Submission status: Runtime Error

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