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

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

wk = 0
for i in range(m):
    x, y, c = map(int, input().split())
    if wk == 0:
        wk = li_a[x - 1] + li_b[y - 1] - c
    else:
        wk = min(wk,li_a[x - 1] + li_b[y - 1] - c)
answer = min(wk,min(li_a) + min(li_b))
print(answer)

Submission status: Wrong Answer

Solution code:
A,B,M=map(int,input().split())
x = [0] * M
y = [0] * M
c = [0] * M
a = [0] * M
b = [0] * M
#0から入ってる
a=input().split()
b=input().split()

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

Submission status: Wrong Answer

Solution code:
A,B,M=map(int,input().split())
x = [0] * M
y = [0] * M
c = [0] * M
a = [0] * M
b = [0] * M
#0から入ってる
a=input().split()
b=input().split()

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

Submission status: Wrong Answer

Solution code:
A,B,M=map(int,input().split())
x = [0] * M
y = [0] * M
c = [0] * M
a = [0] * M
b = [0] * M
#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-1])+int(b[y-1])-c
  if nomal_count>now_count:
    wari_count=now_count
    
print(min(nomal_count,wari_count))

Submission status: Wrong Answer

Solution code:
A, B, m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
l = [input().split() for i in range(m)]
ans = min(a) + min(b)
for i in range(m):
    ai = a[int(l[i][0]) - 1]
    bi = b[int(l[i][1]) - 1]
    ci = int(l[i][2])
    nc = ai + bi - ci
    ans = min(ans, nc)
print(nc)

Submission status: Wrong Answer

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

ans = []
for x,y,c in xyc:
    ans.append(a1[x-1] + b1[y-1] - c)
print(min(ans))

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline().strip('\n').split(' ')
A = input[0]
B = input[1]
M = input[2]

input_A = sys.stdin.readline().strip('\n').split(' ')
bingxiang = list(map(int, input_A))
input_B = sys.stdin.readline().strip('\n').split(' ')
weibolu = list(map(int, input_B))

quan_dict = {}
for line in sys.stdin.readlines():
    quan = list(map(int, line.strip('\n').split(' ')))
    quan_dict[(quan[0], quan[1])] = quan[2]

res = 1e6
for i in range(len(bingxiang)):
    for j in range(len(weibolu)):
        cur = bingxiang[i] + weibolu[j]
        if (i+1, j+1) in quan_dict:
            cur -= quan_dict[(i+1, j+1)]
        res = min(res, cur)

print(res)

Submission status: Wrong Answer

Solution code:
listA=[]

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

    except:
        break;
        

money = min(listA[1]) + min(listA[2]) 
wari = 100000
for k in range(listA[0][2]):
    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: Wrong Answer

Solution code:
listA=[]

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

Solution code:
listA=[] #appendのために宣言が必要
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: Wrong Answer

Solution code:
a, b, m = map(int, input().split())
A_lst = list(map(int, input().split()))
B_lst = list(map(int, input().split()))
dis_lst = [[0]*3 for _ in range(m)]
for i in range(m):
    x, y, c = map(int, input().split())
    dis_lst[0][0] = x - 1
    dis_lst[0][1] = y - 1
    dis_lst[0][2] = c

min_num = min(A_lst) + min(B_lst)
for dis in dis_lst:
    sum_num = A_lst[dis[0]] + B_lst[dis[1]] - dis[2]
    if sum_num < min_num:
        min_num = sum_num

print(min_num)

Submission status: Wrong Answer

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

aMIN = min(a)
bMIN = min(b)

MIN = aMIN + bMIN

for k in data:
    min(MIN, a[k[0]-1]+b[k[1]-1]-k[2])


print(MIN)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#定義
costA = []
costB = []

# ロジック
A,B,M = map(int,input().split()) # A(冷蔵庫)の種類、B(電子レンジ)の種類、M(割引券)の数
x = [[] for i in range(M)]
y = [[] for i in range(M)]
c = [[] for i in range(M)]
costA = input().split()
costB = input().split()
for i in range(M):
  x[i],y[i],c[i] = map(int,input().split()) # x[i]=割引できるA(冷蔵庫)の種類、
                                            # y[i]=割引できるB(電子レンジ)の種類、
                                            # c[i]=割引額
mincostA = int(costA[0])
for j in range(A):
  if int(costA[j]) < mincostA:
    mincostA = int(costA[j])

mincostB = int(costB[0])
for k in range(B):
  if int(costB[k]) < mincostA:
    mincostB = int(costB[k])

teika = mincostA + mincostB

for l in range(M):
  ind1 = x[l] - 1
  out1 = int(costA[ind1]) 
  ind2 = y[l] - 1
  out2 = int(costB[ind2])
  if (out1 + out2 - int(c[l])) < teika:
    teika = (out1 + out2 - int(c[l]))

print(teika)

Submission status: Wrong Answer

Solution code:
#定義
costA = []
costB = []

# ロジック
A,B,M = map(int,input().split()) # A(冷蔵庫)の種類、B(電子レンジ)の種類、M(割引券)の数
x = [[] for i in range(M)]
y = [[] for i in range(M)]
c = [[] for i in range(M)]
costA = input().split()
costB = input().split()
for i in range(M):
  x[i],y[i],c[i] = map(int,input().split()) # x[i]=割引できるA(冷蔵庫)の種類、
                                            # y[i]=割引できるB(電子レンジ)の種類、
                                            # c[i]=割引額
mincostA = int(costA[0])
for j in range(A):
  if int(costA[j]) < mincostA:
    mincostA = int(costA[j])

mincostB = int(costB[0])
for k in range(B):
  if int(costB[k]) < mincostA:
    mincostB = int(costB[k])

teika = mincostA + mincostB

for l in range(M):
  ind1 = x[l] - 1
  out1 = int(costA[ind1]) 
  ind2 = y[l] - 1
  out2 = int(costB[ind2])
  if (out1 + out2 - int(c[l])) < teika:
    print((int(costA[ind1]) + int(costB[ind2])) - int(c[l]))
  else:
    print(teika)

Submission status: Wrong Answer

Solution code:
def main():
  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 = {}
  for i in range(M):
    x,y,c = [int(i) for i in input().split()]
    t = "%s,%s" % (x-1 ,y-1)
    m = 0
    if t in C:
      if C[t] < c:
        C[t] = c
    else:
    	C[t] = c
    if m < c:
      m = c;
  r = 100000;
  for i in range(A):
    for j in range(B):
      z = a[i] + b[j]
      if r < m + z:
        continue
      t = "%s,%s" % (i,j)
      if t in C:
        z = z - C[t]
      if z < r:
        r = z
  print(r)

if __name__ == "__main__":
  main()

Submission status: Wrong Answer

Solution code:
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
discounts = {}
for _ in range(M):
    x, y, c = map(int, input().split())
    x -= 1
    y -= 1
    discounts[(x, y)] = c

ans = float('inf')
for i in range(A):
    for j in range(B):
        tmp = a[i] + b[j]
        if (i, j) in discounts:
            tmp -= discounts[(i, j)]
        ans = min(ans, tmp)
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
S = input()
for i in range(6):
    x = 'hi'*i
    if S == x:
        print('Yes')
        break;
else:
    print('No')

Submission status: Wrong Answer

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-1] + bB[y-1] - c
  if cost < ans:
    ans = cost
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

for i in range(M):
    combi = list(map(int, input().split(' ')))
    sum = (priceA[combi[0]-1] + priceB[combi[1]-1] - combi[2])
    if minPrice is None:
      minPrice = sum
    elif minPrice > sum:
      minPrice = sum
else:      
    print(minPrice)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

Submission status: Wrong Answer

Solution code:
import numpy as np

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

Submission status: Wrong Answer

Solution code:
import numpy as np

A,B,M = list(map(int,input().split()))
valueA = list(map(int, input().split()))
#print(valueA)
valueB = list(map(int, input().split()))
#print(valueB)
tickets = np.zeros((M ,3))
for i in range(M):
    tickets[i,:] =  list(map(int, input().split()))
x1 = int(tickets[0,0])
y1 = int(tickets[0,1])
c1 = int(tickets[0,2])
min_ticket = valueA[x1-1] + valueB[y1-1] - c1
for i in range(2,M):
    xi = int(tickets[i,0])
    yi = int(tickets[i,1])
    ci = int(tickets[i,2])
    value = valueA[xi-1] + valueB[yi-1] - ci
    if value < min_ticket:
        min_ticket = value
min_itself = valueA[0] + valueB[0]
for i in range(A):
    for j in range(B):
        value = valueA[i] + valueB[j]
        if value < min_itself:
            min_itself = value
min_all = min(min_itself, min_ticket)
print(min_all)

Submission status: Wrong Answer

Solution code:
import sys

def disscount(disscounts,x,y):
  for i in disscounts:
    if int(i[0]) == x and int(i[1]) == y:
      return int(i[2])
  return 0

counts = input().split()
colors = input().split()
hots = input().split()
disscounts = []
for i in range(int(counts[2])):
  disscounts.append(input().split())

minPrice = sys.maxsize
for i in range(0, len(colors) -1):
  for j in range(0, len(hots) -1):
    colorPrice = int(colors[i])
    hotPrice = int(hots[j])
    price = colorPrice + hotPrice - disscount(disscounts, i + 1 , j + 1)
    if price < minPrice:
      minPrice = price
print(str(minPrice))

Submission status: Wrong Answer

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

# m 初期化
# m = [[0] * 3 for i in range(nm)]
d = [[] for _ in range(na)]
print(d)

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

#  m入力
for k in range(nm):
    i,j,disc = map(int, input().split())
    d[i-1].append([j-1,disc])

#print(d)

best = a[0] + b[0]

for i in range(na):
    for j in range(nb):
        disc = 0
        for k in d[i] :
            if j == k[0] and disc < k[1]:
                disc =k[1]
        price = a[i] + b[j] - disc
        if best > price:
            best = price

print(best)

Submission status: Wrong Answer

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

# m 初期化
# m = [[0] * 3 for i in range(nm)]
d = [[0] * nb for i in range(na)]
#print(d)

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

#  m入力
for k in range(nm):
    i,j,disc = map(int, input().split())
    if d[i-1][j-1] < disc:
        d[i-1][j-1] = disc
print(d)

best = a[0] + b[0]

for i in range(na):
    for j in range(nb):
        price = a[i] + b[j] - d[i][j]
        if best > price:
            best = price

print(best)

Submission status: Wrong Answer

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

print(ans)

Submission status: Wrong Answer

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

ans = min(ref) + min(ran)

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

Submission status: Wrong Answer

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

ans = min(ref) + min(ran)

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

Submission status: Wrong Answer

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

# m 初期化
m = [[0]*3 for i in range(nm)]
# print(m)

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

#  m入力
for i in range(nm):
    m[i] = list(map(int, input().split()))
#    print('discount => '+str(m[i][0])+str(m[i][1])+str(m[i][2]))
#print('discount data')
#print(m)

#print('start = ')
best = a[0] + b[0]

for i in range(na):
    for j in range(nb):
        disc = 0
        for k in range(nm):
#            print(i,j,k)
            if m[k][0]==i and m[k][1]==j:
                if disc < m[k][2]:
                    disc = m[k][2]
#                print(i,j,k)
#                print('HIT HIT')
        price = a[i] + b[j] - disc

        if best > price:
            best = price

print(best)

Submission status: Wrong Answer

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

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

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

print(min(l))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def main():
    A,B,M = map(int,input().split())
    val_a = [int(i) for i in input().split()]
    val_b = [int(j) for j in input().split()]
    lucky = [map(int,input().split()) for _ in range(M)]
    min_a = min(val_a)
    min_b = min(val_b)
    ans = min_a + min_b
    for i in range(M):
        a,b,c = lucky[i]
        p = val_a[a-1] + val_b[b-1] - c
        if p < ans:
            ans = p
    print(p)
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from sys import stdin

A, B, M = (int(x) for x in stdin.readline().rstrip().split())
ai = [int(x) for x in stdin.readline().rstrip().split()]
bj = [int(x) for x in stdin.readline().rstrip().split()]

minimum = int()
for i in range(M):
    x, y, c = (int(x) for x in stdin.readline().rstrip().split())
    price = ai[x-1] + bj[y-1] - c
    if i == 0:
        minimum = price
    if price < minimum:
        minimum = price

print(minimum)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:


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

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

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

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

ans = an[0] + bn[0]
for i in range(m):
    p, q, discount = [int(x) for x in input().split()]
    a_cost = an[p-1]
    b_cost = bn[q-1]
    total = a_cost + b_cost - discount
    ans = min(total, ans)

print(ans)

Submission status: Wrong Answer

Solution code:


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

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

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

ans = an[0] + bn[0]
for (a_index,b_index),discount in discounts.items():
    a_cost = an[a_index-1]
    b_cost = bn[b_index-1]
    total = a_cost + b_cost - discount
    ans = min(total, ans)

print(ans)

Submission status: Wrong Answer

Solution code:


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

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

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


i = 0
j = 0
min = 999999

for (a_index,b_index),discount in discounts.items():
    a_cost = an[a_index-1]
    b_cost = bn[b_index-1]
    total = a_cost + b_cost - discount
    if min > total:
        min = total
if min == 999999:
    print(an[0]+b[0])
else:
    print(min)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

min = min(a) + min(b)

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

print(min)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:


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

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

discounts = {}
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


i = 0
j = 0
min = 999999

for (a_index,b_index),discount in discounts.items():
    a_cost = an[a_index-1]
    b_cost = bn[b_index-1]
    total = a_cost + b_cost - discount
    if min > total:
        min = total
if min == 999999:
    print(an[0]+b[0])
else:
    print(min)

Submission status: Wrong Answer

Solution code:


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

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

discounts = {}
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


i = 0
j = 0
min = an[0]+bn[0]

for (a_index,b_index),discount in discounts.items():

    a_cost = an[a_index-1]
    b_cost = bn[b_index-1]
    total = a_cost + b_cost - discount
    if min > total:
        min = total

print(min)

Submission status: Wrong Answer

Solution code:
x,y,m = map(int,input().split());an=10**9
p=list(map(int,input().split()));q=list(map(int,input().split()))
for i in range(m):
  a,b,c = map(int,input().split())
  an=min(an,p[a-1]+q[b-1]-c)
print(an)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys

def disscount(disscounts,x,y):
  for i in disscounts:
    if int(i[0]) == x and int(i[1]) == y:
      return int(i[2])
  return 0

counts = input().split()
colors = input().split()
hots = input().split()
disscounts = []
for i in range(int(counts[2])):
  disscounts.append(input().split())

minPrice = sys.maxsize
for i in range(0, len(colors) -1):
  for j in range(0, len(hots) -1):
    colorPrice = int(colors[i])
    hotPrice = int(hots[j])
    price = colorPrice + hotPrice - disscount(disscounts, i + 1 , j + 1)
    if price < minPrice:
      minPrice = price
print(str(minPrice))

Submission status: Wrong Answer

Solution code:
A, B, M = [int(n) for n in input().split()]
a  = [int(n) for n in input().split()]
b = [int(n) for n in input().split()]
ma = sorted(a)[0]
mb = sorted(b)[0]
XY = {}
ans = 10**5+1
for m in range(M):
    x, y, c = [int(n) for n in input().split()]
    dv = a[x-1] + b[y-1] - c
    mv = min((ma+mb), dv)
    if ans > mv:
        ans = mv
print(ans)

Submission status: Wrong Answer

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())
        xyc.append([x, y, c])
    # print(A)
    # print(B)
    # print(xyc)

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

Submission status: Wrong Answer

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())
        xyc.append([x, y, c])
    # print(A)
    # print(B)
    # print(xyc)

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

Submission status: Wrong Answer

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

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
#             if k == M:
#                 k = 0
#             continue;
#         cost = a[i] + b[j]
#         if cost < min:
#             min = cost

print(min)