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:
A,B,M=map(int,input().split())
#0から入ってる
a=input().split()
b=input().split()

#ただの最小
mina=int(min(a))
minb=int(min(b))
nomal_count=mina+minb
#割引
wari_count=0
for i in range(M):
  x,y,c=map(int,input().split())
  now_count=int(a[x])+int(b[y])-c
  if wari_count<now_count:
    wari_count=now_count
    
print(max(nomal_count,wari_count))

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()))
l = [map(int, input().split()) for i in range(m)]
ans = min(a) + min(b)
for i in range(m):
    ai = a[l[i][0] - 1]
    bi = b[l[i][0] - 1]
    ci = c[l[i][0] - 1]
    nc = ai + bi - c
    ans = min(ans, nc)
print(nc)

Submission status: Runtime Error

Solution code:
while True:
    try:
        listA.append(list(map(int,input().split())))

    except:
        break;
        

money = min(listA[1]) + min(listA[2]) 

for k in range(listA[0][2]):
    wari = 1000
    a = listA[k+3][0]
    b = listA[k+3][1]
    if wari > listA[1][a-1] + listA[2][b-1] - listA[k+3][2]:
        wari = listA[1][a-1] + listA[2][b-1] - listA[k+3][2]

if money <= wari:
    print(money)
        
else:
    print(wari)

Submission status: Runtime Error

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

ans = min(a) + min(b)

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

Submission status: Runtime Error

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

ans = min(a) + min(b)

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

Submission status: Runtime Error

Solution code:
a,b,m=map(int,input().split())
A=input().split()
B=input().split()
AA=[]
for i in range(len(A)):
	AA.append(int(A[i]))
BB=[]
for i in range(len(B)):
	BB.append(int(B[i]))
C=[]
for i in range(m):
	x,y,c=map(int,input().split())
	C.append(AA[x]+BB[y]-c)
C.append(min(AA)+min(BB))
print(min(C))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:

import numpy as np
A, B, M = map(int, input().split())
a = np.array([int(i) for i in input().split()], dtype=int)
b = np.array([int(i) for i in input().split()], dtype=int)
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] = map(int, input().split())

non_coupon_val = np.min(a) + np.min(b)
coupon_val_arr = np.zeros(M)
for i in range(M):
  coupon_val_arr[i] = a[x[i]] + b[y[i]] - c[i]
  coupon_val = np.min(coupon_val_arr)
print(np.min([non_coupon_val, coupon_val]))

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

ans=99999999999
for i in range(a):
    for j in range(i,b)::
        ans=min(ans,A[i]+B[j])
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: 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')

disc=list()
disc_A_dict = dict()
for n in range(M):
    (x,y,c)=map(int,input().split())
    disc.append([x,y,c])
    disc_A_dict[x]=1

dc_index=dict()
dc=np.zeros((len(disc_A_dict),B),dtype='int32')

k=0
for n in range(M):
    (x,y,c)=disc[n]
    i=x-1
    j=y-1
    if i not in dc_index:
        dc_index[i]=k
        k+=1

    if c > dc[dc_index[i],j]:
        dc[dc_index[i],j]=c

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

min_p = prices_A[0] + prices_B[0]
for i in range(A):
    if i in dc_index:
        price_B_dc=prices_B-dc[dc_index[i]]
        p=prices_A[i]+price_B_dc.min()
    else:
        p=prices_A[i]+prices_B.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=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]

ans=99999999999
for i a:
    for j in b:
        ans=min(ans,i+j)
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: Runtime Error

Solution code:
import sys
import numpy as np

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

m=max(100,int(A/10))

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

dc_index=dict()
dc=np.zeros((m,B),dtype='int32')

k=0
for n in range(M):
    (x,y,c)=map(int,input().split())
    i=x-1
    j=y-1
    if i not in dc_index:
        dc_index[i]=k
        # prepare for next one
        k+=1
        if k % m == 0:
            dc=np.concatenate([dc, np.zeros((m,B),dtype='int32')],axis=0)

    if c > dc[dc_index[i],j]:
        dc[dc_index[i],j]=c

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

min_p = prices_A[0] + prices_B[0]
for i in range(A):
    if i in dc_index:
        price_B_dc=prices_B-dc[dc_index[i]]
        p=prices_A[i]+price_B_dc.min()
    else:
        p=prices_A[i]+prices_B.min()
        
    if p < min_p:
        min_p=p
print(min_p)

Submission status: Runtime Error

Solution code:
import sys
import numpy as np

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

m=max(1000,int(M/10))

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

dc_index=dict()
dc=np.zeros((m,B),dtype='int32')

k=0
for n in range(M):
    (x,y,c)=map(int,input().split())
    i=x-1
    j=y-1
    if i not in dc_index:
        dc_index[i]=k
        # prepare for next one
        k+=1
        if k % m == 0:
            dc=np.concatenate([dc, np.zeros((m,B),dtype='int32')],axis=0)

    if c > dc[dc_index[i],j]:
        dc[dc_index[i],j]=c

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

min_p = prices_A[0] + prices_B[0]
for i in range(A):
    if i in dc_index:
        price_B_dc=prices_B-dc[dc_index[i]]
        p=prices_A[i]+price_B_dc.min()
    else:
        p=prices_A[i]+prices_B.min()
        
    if p < min_p:
        min_p=p
print(min_p)

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_index=dict()
dc=np.zeros((M,B),dtype='int32')

k=0
for n in range(M):
    (x,y,c)=map(int,input().split())
    i=x-1
    j=y-1
    if i not in dc_index:
        dc_index[i]=k
        k+=1
    if c > dc[dc_index[i],j]:
        dc[dc_index[i],j]=c

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

min_p = prices_A[0] + prices_B[0]
for i in range(A):
    if i in dc_index:
        price_B_dc=prices_B-dc[dc_index[i]]
        p=prices_A[i]+price_B_dc.min()
    else:
        p=prices_A[i]+prices_B.min()
        
    if p < min_p:
        min_p=p
print(min_p)

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_index=dict()
dc=np.zeros((M,B),dtype='int32')

k=0
for n in range(M):
    (x,y,c)=map(int,input().split())
    i=x-1
    j=y-1
    if i not in dc_index:
        dc_index[i]=k
        k+=1
    if c > dc[dc_index[i],j]:
        dc[dc_index[i],j]=c

print(prices_A)
print(prices_B)
print(dc)
print(dc_index)

min_p = prices_A[0] + prices_B[0]
for i in range(A):
    if i in dc_index:
        price_B_dc=prices_B-dc[dc_index[i]]
        p=prices_A[i]+price_B_dc.min()
    else:
        p=prices_A[i]+prices_B.min()
        
    if p < min_p:
        min_p=p
print(min_p)

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_index=dict()
dc=np.zeros((M,B),dtype='int32')

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

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

min_p = prices_A[0] + prices_B[0]
for i in range(A):
    if i in dc_index:
        price_B_dc=prices_B-dc[dc_index[i]]
        p=prices_A[i]+price_B_dc.min()
    else:
        p=prices_A[i]+prices_B.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 = list(map(int,input().split()))
b_list = list(map(int,input().split()))
C_list = []
for i in range(M):
  x,y,c = map(int,input().split())
  C_list.append([x,y,c])

a_list_min = min(a_list)
b_list_min = min(b_list)

best_sum = a_list_min + b_list_min
c_sum_list=[]

for r in C_list:
  instant_sum = a_list[r[0]-1] + b_list[r[0]-1] - r[2]
  best_sum = min(best_sum,instant_sum)

print(best_sum)

Submission status: Runtime Error

Solution code:
A,B,M = map(int,input().split())
a_list = list(map(int,input().split()))
b_list = list(map(int,input().split()))
C_list = []
for i in range(M):
  x,y,c = map(int,input().split())
  C_list.append([x,y,c])

a_list_min = min(a_list)
b_list_min = min(b_list)

best_sum = a_list_min + b_list_min
c_sum_list=[]

for r in C_list:
  instant_sum = a_list[r[0]-1] + b_list[r[0]-1] - r[2]
  if best_sum > instant_sum:
    best_sum = instant_sum

print(best_sum)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
A, B, M = map(int, input().split())
aA = list(map(int, input().split())) 
bB = list(map(int, input().split())) 
ans = float('inf')
for i in range(M):
  x, y, c = map(int, input().split())
  cost = aA[x] + bB[y] - c
  if cost < ans:
    ans = cost
print(ans)

Submission status: Runtime Error

Solution code:
A, B, M = map(int, input().split())
aA = list(map(int, input().split())) 
bB = list(map(int, input().split())) 
x = []
y = []
c = []
ans = float('inf')
for i in range(M):
  x[i], y[i], c[i] = map(int, input().split())
  cost = aA[x[i]] + bB[y[i]] - c[i]
  if cost < ans:
    ans = cost
print(ans)

Submission status: Runtime Error

Solution code:
A, B, M = map(int, input().split())
aA = list(map(int, input().split())) 
bB = list(map(int, input().split())) 
x = []
y = []
c = []
ans = float('inf')
for i in range(M):
  x[i], y[i], c[i] = map(int, input().split())
  cost = A[x[i]] + B[y[i]] - c[i]
  if cost < ans:
    ans = cost
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
a,b,m = map(int,input().split())
ref = list(map(int,input().split()))
ran = list(map(int,input().split()))
ticket = []
ans = min(ref) + min(ran)
for i in range(m):
  t = list(map(int,input().split()))
  p = t[0] - 1
  q = t[1] - 1
  if ref[p] + ran[p] < ans:
    ans = ref[p] + ran[p]
print(ans)

Submission status: Runtime Error

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

al=[]
a=input().split()
for i in a:
    al.append(int(i))
bl = []
b=input().split()
for i in b:
    bl.append(int(i))
l=[]
cl=[]
for i in range(M):
    c = input().split()
    for i in c:
        l.append(int(i))
    cl.append(l)

l=[]
for cl in cl:
    a=0
    a=al[cl[0]]+bl[cl[1]]-cl[2]
    l.append(a)

print(min(a))

Submission status: Runtime Error

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

al=[]
a=input().split()
for i in a:
    al.append(int(i))
bl = []
b=input().split()
for i in b:
    bl.append(int(i))
l=[]
cl=[]
for i in range(M):
    c = input().split()
    for i in c:
        l.append(int(i))
    cl.append(l)

l=[]
for cl in cl:
    a=0
    a=al[cl[0]]+bl[cl[1]]-cl[2]
    l.append(a)

print(a)

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(" ")))
tmp = 1000000000
for i in range(M):
    c = int(input())
    sum1 = a[i]+b[i]-c
    ans = min(tmp,sum1)
print(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(",")))
tmp = 1000000000
for i in range(M):
    c = int(input())
    sum1 = a[i]+b[i]-c
    ans = min(tmp,sum1)
print(ans)

Submission status: Runtime Error

Solution code:
A = list(map(int,input().split()))
B = list(map(int,input().split()))
M = int(input())
C = [list(map(int,input().split())) for _ in range(M)]
ans = min(A) + min(B)
for cp in C:
    temp = A[cp[0]-1] + B[cp[1]-1] + cp[2]
    ans = min(ans,temp)
    
print(ans)

Submission status: Runtime Error

Solution code:
A, B, M = list(map(int,input().split()))
list_a = list(map(int,input().split()))
list_b = list(map(int,input().split()))
for i in range(M):
    x, y, c = list(map(int,input().split()))
buy = []
buy.append(min(list_a) + min(list_b))
buy.append(list_a[x] + list_b[y] - c)
answer = min(buy)
print(answer)

Submission status: Runtime Error

Solution code:
A, B, M = list(map(int,input().split()))
list_a = list(map(int,input().split()))
list_b = list(map(int,input().split()))
for i in range(M):
    x, y, c = list(map(int,input().split()))
buy = []
buy.append(min(list_a) + min(list_b))
buy.append(list_a[x] + list_b[y] - c)
answer = min(buy)
print(answer, buy)

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

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):
  new_ans = a[x[i] - 1] + b[x[i] - 1] - c[i]
  ans = min(ans, new_ans)


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

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):
  new_ans = a[x[i] - 1] + b[x[i] - 1] - c[i]
  ans = min(ans, new_ans)

print(ans)

Submission status: Runtime Error

Solution code:
def resolve():
    input = sys.stdin.readline
    A, B, M = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    grid=[list(map(int,input().split())) for i in range(M)]

    res = min(a) + min(b)

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

    print(res)
    
resolve()

Submission status: Runtime Error

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 discount in sys.stdin:
    x, y, c = map(int, discount.split())
    ans = min(ans, a_list[x - 1] + b_list[y - 1] - c)
print(ans)

Submission status: Runtime Error

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

x, y, m = [int(i) for i in input().split()]

a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
num = [min(a)+min(b)]

for _ in range(m):
    tmp = [int(i) for i in input().split()]
    num.append(a[tmp[0]]-1+b[tmp[1]]-1-tmp[2])

print(min(num))

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

index = 0
for i in range(M):
    hikaku = aryAPrice[aryDiscount[index,0]] + aryBPrice[aryDiscount[index,1]] - aryDiscount[index,2]
    if bestSum > hikaku:
        bestSum = hikaku

    index += 1

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)
mem2 = []
for x, y, c in z:
    mem2.append(a[x - 1] + b[y - 1] - c)
np.append(mem, mem2)


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

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



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

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

ans = list(ans)

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

Submission status: Runtime Error

Solution code:
A,B,M = map(int,input().split())
a =[int(s) for s in input().split()]
b =[int(p) for p in input().split()]
em = []
for m in range(M):
  x,y,c= map(int,input().split())
  em += a[x]+b[y]-c
  exit()
 
print(min[min(a)+min(b),min(em)])

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)
mem2 = []
for x, y, c in z:
    mem2.append(a[x - 1] + b[y - 1] - c])
np.append(mem, mem2)


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

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

cut_map = numpy.zeros((A,B))
for i in range(M):
    [inx, iny, inc] = list(map(int, input().split()))
    if cut_map[inx-1,iny-1] > -inc:
        cut_map[inx-1,iny-1] = -inc

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

print(int(numpy.min(cut_map)))

Submission status: Runtime Error

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

reizou = input()
reizou_list = reizou.split()

renji = input()
renji_list = renji.split()
cupon_list = []

price = int(min(reizou_list)) + int(min(renji_list))

for i in range(int(M)):
    # coupon = input()
    # coupon_sub_list = coupon.split()
    # cupon_list.append(coupon_sub_list)
    
    a,b,c = map(int,input().split())
    price_coupon = int(reizou_list[a]) + int(renji_list[b]) - int(c)
    if price > price_coupon: price = price_coupon

print(price)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

reizou = input()
reizou_list = reizou.split()

renji = input()
renji_list = renji.split()
cupon_list = []

price = int(min(reizou_list)) + int(min(renji_list))

for i in range(int(M)):
    # coupon = input()
    # coupon_sub_list = coupon.split()
    # cupon_list.append(coupon_sub_list)
    
    a,b,c = map(int,input().split())
    price_coupon = int(reizou_list[a]) + int(renji_list[b]) - int(c)
    if price > price_coupon: price = price_coupon

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()))
c=[]
wari=[]
warik=0
ans=0
for i in range(M):
    c+=list(map(int, input().split()))
for i in range(M):
    wari.append(a[c[i*3]]+b[c[(2*i+1)]]-c[2*i+2])
warik=min(wari)
ans=min(a)+min(b)
if ans>warik:
    print(warik)
else:
    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 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)
    np.append(mem, [a[x - 1] + b[y - 1] - c])


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

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

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:
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 = 10000000000

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



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

b2 = np.array(b1)
a2 = np.array(a1)
a2 = a2.reshape(a,1)
ans = list(ans)
print(min( min(ans), np.min(a2+b2) ))

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

#cut_map = [[0*i for i in range(B)] for j in range(A)]
cut_map = np.zeros((A,B))
for i in range(M):
    [inx, iny, inc] = list(map(int, input().split()))
    if cut_map[inx-1,iny-1] > -inc:
        cut_map[inx-1,iny-1] = -inc

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

print(int(np.min(cut_map)))

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:
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:
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)
    np.append(mem, (a[x - 1] + b[y - 1] - c))


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

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:

input = input()

price = {}
lowest1 = 100000
my_price = 0


def trans(s):
    return int(s)


def split_with_blank(row):
    return row.split(" ")


arr = input.split('\n')
arr2 = list(map(split_with_blank, arr))

for index1, obj, in enumerate(arr2):
    for index2, st, in enumerate(obj):
        #print(st)
        arr2[index1][index2] = int(st)

A = arr2[0][0]
B = arr2[0][1]
M = arr2[0][2]
price = {
    "a": arr2[1],
    "b": arr2[2]
}

coupons = arr2[3:]


def vali(coupon):
    my_price = price["a"][coupon[0] - 1] + \
        price["b"][coupon[1] - 1] - coupon[2]
        
    global lowest1

    if my_price < lowest1:
        lowest1 = my_price


map(vali, coupons)

lowest2 = min(price["a"]) + min(price["b"])

if lowest1 <= lowest2:
    print(lowest1)
else:
    print(lowest2)

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)