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())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
x = []
y = []
c = []
for _ in range(M):
    X,Y,Z = map(int,input().split())
    x.append(X)
    y.append(Y)
    c.append(Z)

mini = min(a) + min(b)
for i in range(M):

    rei = a[x[i]-1]
    den = b[y[i]-1]
    coop = c[i-1]

    if rei + den - coop < mini:
        mini = rei + den - coop

print(mini)

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 = []
y = []
c = []
for _ in range(M):
    X,Y,Z = map(int,input().split())
    x.append(X)
    y.append(Y)
    c.append(Z)

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

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

Submission status: Wrong Answer

Solution code:
a, b, m = map(int, input().split())
re = sorted(list(map(int, input().split())))
de = sorted(list(map(int, input().split())))
list1 = []
for i in range(m):
  x, y, c = map(int, input().split())
  price = re[x-1] + de[y-1] -c
  list1.append(price)
mlist = min(list1)
m1 = re[0] + de[0]

if m1 < mlist:
  print(m1)
else:
  print(mlist)

Submission status: Wrong Answer

Solution code:
a, b, m = map(int, input().split())
re = sorted(list(map(int, input().split())))
de = sorted(list(map(int, input().split())))
list1 = []
for i in range(m):
  x, y, c = map(int, input().split())
  price = re[x-1] + de[y-1] -c
  list1.append(price)

if re[0] + de[0] < min(list1):
  print(re[0] + de[0])
else:
  print(min(list1))

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()))
C=[]
D=[]
for i in range(len(a)):
    C.append([])
xyc=[]
for i in range(M):
    xyc.append(list(map(int,input().split())))
for i in range(len(a)):
    for j in range(len(b)):
        C[i].append(a[i]+b[j])
        for k in range(M):
            if i==xyc[k][0] and j==xyc[k][1]:
                C[i][j]-=xyc[k][2]
for i in range(len(a)):
    for j in range(len(b)):
        D.append(C[i][j])
print(min(D))

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

Submission status: Wrong Answer

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

#割引券を使う場合
best_M_idx = C.index(max(C))
pay_M = a[X[best_M_idx]-1] + b[Y[best_M_idx]-1]-max(C)
#使わない場合
pay = min(a) + min(b)
print(min(pay,pay_M))

Submission status: Wrong Answer

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

#割引券を使う場合
best_M_idx = C.index(max(C))
pay_M = a[X[best_M_idx]-1] + b[Y[best_M_idx]-1]-max(C)
#使わない場合
D = [i + j for i,j in zip(a,b)] 
pay = min(D)
print(min(pay,pay_M))

Submission status: Wrong Answer

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

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

ans = 99999999999999999999
for k, v in cs.items():
  x = a[k[0]]
  y = b[k[1]]
  cost = x + y - v
  ans = min(ans, cost)

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

print(ans)

Submission status: Wrong Answer

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

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

ans = 1 << 11
for i, x in enumerate(a):
  for j, y in enumerate(b):
    cost = x + y
    if (i, j) in cs:
      cost -= cs[(i, j)]
    ans = min(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()))

vals = []
for _ in range(M):
    i, j, v = map(int, input().split())
    print(i, j, v)
    vals.append( a[i - 1] + b[j - 1] - v)

vals.append(min(a) + min(b))
print(min(vals))

Submission status: Wrong Answer

Solution code:
def resolve():
    a, b, m = map(int, input().split())
    a_list = sorted(list(map(int, input().split())))
    b_list = sorted(list(map(int, input().split())))
    ans = min(a_list) + min(b_list)
    for _ in range(m):
        x, y, c = map(int, input().split())
        ans = min(ans, a_list[x-1]+b_list[y-1]-c)
    print(ans)
resolve()

Submission status: Wrong Answer

Solution code:
def resolve():
    a, b, m = map(int, input().split())
    a_list = sorted(list(map(int, input().split())))
    b_list = sorted(list(map(int, input().split())))
    min_a = min(a_list)
    min_b = min(b_list)
    min_total = min_a + min_b
    for _ in range(m):
        x, y, c = map(int, input().split())
        a_c = a_list[x-1]
        b_c = b_list[y-1]
        min_total = min(min_total, a_c + b_c - c)
    print(min_total)
resolve()

Submission status: Wrong Answer

Solution code:
def resolve():
    a, b, m = map(int, input().split())
    a_list = sorted(list(map(int, input().split())))
    b_list = sorted(list(map(int, input().split())))
    min_total = min(a_list) + min(b_list)
    for _ in range(m):
        x, y, c = map(int, input().split())
        a_c = a_list[x-1]
        b_c = b_list[y-1]
        if min_total > a_c + b_c - c:
            min_total = a_c + b_c - c
    print(min_total)
resolve()

Submission status: Wrong Answer

Solution code:
def resolve():
    a, b, m = map(int, input().split())
    a_list = sorted(list(map(int, input().split())))
    b_list = sorted(list(map(int, input().split())))
    min_total = min(a_list) + min(b_list)
    for _ in range(m):
        x, y, c = map(int, input().split())
        a_c = a_list[x-1]
        b_c = b_list[y-1]
        if min_total > a_c + b_c - c:
            min_total = a_c + b_c - c
    print(min_total)

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=10**5+10**5
for i in range(m):
    x,y,c=map(int,input().split())
    num=A[x-1]+B[y-1]-c
    ans=min(num,ans)
print(ans)

Submission status: Wrong Answer

Solution code:
(A, B, M), aa, bb, *xyc = [list(map(int, s.split())) for s in open(0)]

ans = min(aa)+min(bb)

for x, y, c in xyc:
    ans = min(ans, aa[x-1]+bb[y-1]-c)

ans

Submission status: Wrong Answer

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

price_A = list(map(int, input().split()))
price_B = list(map(int, input().split()))

ans = 10**6

for m in range(M):
  x, y, c = map(int, input().split())
  p1 = price_A[x-1] + price_B[y-1] - c
  p2 = price_A[x-1] + price_B[y-1]
  if p1 <= p2 and p1 <= ans: ans=p1
  elif p2 <= p1 and p2<= ans: ans=p2

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
a,b,m = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
ans = sys.maxsize
summoney = 0
for i in range(m):
  x,y,c = map(int,input().split())
  summoney = a[x-1] + b[y-1] - c
  ans = min(ans,summoney)

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

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

Submission status: Wrong Answer

Solution code:
#from itertools import  product

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

mlist = {}
for i in range(M):
  mtmp = [ int(i) for i in input().split() ] 
  mlist[str(mtmp[0])+"-" + str(mtmp[1])] = mtmp[2]

minPrice =  (10**5)*2
for k1,v1 in enumerate(a):
  for k2,v2 in enumerate(b):
     if str(k1+1) + "-" +  str(k2+1) in mlist :
       price = v1+v2 - mlist[str(k1+1) + "-" +  str(k2+1)]
     else: 
       price = v1+v2 

     minPrice = min(price, minPrice)

print(minPrice)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def resolve():
    A, B, M = list(map(int, input().split()))
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    a.sort()
    b.sort()
    x, y, c = [], [], []

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

    dis.sort()
    print(min(a[0]+b[0], dis[0]))

    return

resolve()

Submission status: Wrong Answer

Solution code:
res = float("inf")
d = dict()
A , B, M = map(int,input().split(" "))
a = list(map(int,input().split(" ")))
b = list(map(int,input().split(" ")))
for _ in range(M):
    x,y, c = list(map(int,input().split(" ")))
    d[(x-1,y-1)] = c
for i in range(A):
    for j in range(B):
        curr = a[i] + b[j]
        if (i,j) in d:
            curr -= d[(i,j)]
        res = min(res,curr)

print(res)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys


def solve(
    A: int,
    B: int,
    M: int,
    a: "List[int]",
    b: "List[int]",
    x: "List[int]",
    y: "List[int]",
    c: "List[int]",
):
    # 引数大杉ぃ
    min_refrigerator = min(a)
    min_microwave = min(b)
    not_use_coupon = min_refrigerator + min_microwave

    max_sale = max(c)
    use_coupon = 200000
    for xi, yi, ci in zip(x, y, c):
        # 複数ある場合があるので最小を複数保持っておく
        if ci == max_sale:
            use_coupon = min(use_coupon, a[xi - 1] + b[yi - 1] - ci)

    ans = min(use_coupon, not_use_coupon)
    print(ans)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(A)]  # type: "List[int]"
    b = [int(next(tokens)) for _ in range(B)]  # type: "List[int]"
    x = [int()] * (M)  # type: "List[int]"
    y = [int()] * (M)  # type: "List[int]"
    c = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        x[i] = int(next(tokens))
        y[i] = int(next(tokens))
        c[i] = int(next(tokens))
    solve(A, B, M, a, b, x, y, c)


if __name__ == "__main__":
    main()

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()))
li_c = []
for _ in range(m):
  x, y, c = map(int, input().split())
  x, y = x-1, y-1
  li_c.append(li_a[x]+li_b[y]-c)
li_a.sort()
li_b.sort()
li_c.sort()
ans = min(li_a[0]+li_b[0], li_c[0])

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

Solution code:
a,b,m = map(int,input().split())
alist = list(map(int,input().split()))
blist = list(map(int,input().split()))
mlist = [list(map(int,input().split())) for s in range(m)]
for m in mlist:
	tmp = alist[m[0]-1] + blist[m[1]-1] -m[2]
	ans = [tmp]
for a in alist:
	for b in blist:
		ans.append(a + b)
print(min(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()))

c = [[0 for _ in range(B)] for _ in range(A)]
for _ in range(M):
    x, y, cp = map(int,input().split())
    c[x-1][y-1] = cp

oldp = 10**20
for an in range(A):
    for bn in range(B):
        if c[an][bn] == 0: continue
        p = a[an]+b[bn]-c[an][bn]
        if oldp > p:
            oldp = p

p = min(a)+min(b)
print(min(oldp,p))

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

c = [[0 for _ in range(B)] for _ in range(A)]
for _ in range(M):
    x, y, cp = map(int,input().split())
    c[x-1][y-1] = cp

oldp = 10**20
for an in range(A):
    for bn in range(B):
        p = a[an]+b[bn]-c[an][bn]
        if oldp > p:
            oldp = p

print(oldp)

Submission status: Wrong Answer

Solution code:

def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def s4(n):return [[x for x in s] for s in s2(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes if b else no)
# from sys import setrecursionlimit
# setrecursionlimit(1000000)
# from collections import Counter,deque,defaultdict
# import itertools
# import math
# import networkx as nx
# from bisect import bisect_left,bisect_right
# from heapq import heapify,heappush,heappop
a,b,m=n1()
A=n1()
B=n1()
X=n3(m)

A.sort()
B.sort()
ans=A[0]+B[0]
for a,b,c in X:
    if A[a-1]+B[b-1]-c<ans:
        ans=A[a-1]+B[b-1]-c
    
print(ans)

Submission status: Wrong Answer

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()]
min = A[0]+B[0]
for i in range(M):
  x,y,c = [int(i) for i in input().split()]
  buf = A[x-1]+B[y-1]-c
  if buf<min:
    min = buf
print(min)

Submission status: Wrong Answer

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()]
min = A[0]+B[0]
for i in range(M):
  x,y,c = [int(i) for i in input().split()]
  buf = A[x-1]+B[y-1]-c
  print(A[x-1],B[y-1],c)
  if buf<min:
    min = buf
print(min)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

rets = [ai+bi for ai, bi in zip(a, b)]

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

Submission status: Wrong Answer

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

for _ in range(m):
    x, y, c = map(int, input().split())
    x -= 1
    y -= 1
    total = a_list[x] +b_list[y] - c
    money.append(total)
print(min(money))

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()))
a.sort()
b.sort()
ans = a[0] + b[0]

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

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

a.sort()
b.sort()
no_ticket = a[0] + b[0]

ticket = 10**5
for i in range(M):
    ticket2 = a[x[i]-1] + b[y[i]-1] - c[i]
    ticket = min(ticket, ticket2)

print(min(no_ticket, ticket))

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

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

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

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
import numpy as np

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

C = defaultdict(int)

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

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

for c in C:
    ans = min(ans, a[c[0]] + b[c[1]] - C[c])
    
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
import numpy as np

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

C = defaultdict(int)

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

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

for c in C:
    ans = min(ans, a[c[0]] - b[c[1]] - C[c])
    
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

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

C = defaultdict(int)

for i in range(M):
    x, y, c = map(int, input().split())
    C[tuple([x, y])] = c

ans = float("inf")

for i in range(len(a)):
    for j in range(len(b)):
        ans = min(ans, a[i] + b[j] - C[(i+1, j+1)])

print(ans)

Submission status: Wrong Answer

Solution code:
A,B,M=map(int, input().split())
As=list(map(int, input().split()))
Bs=list(map(int, input().split()))
List=[]

ans=min(As)+min(Bs)
for i in As:
  for j in Bs:
    ans=min(ans, i+j)
for l in List:
  candidate=As[l[0]-1]+Bs[l[1]-1]-l[2]
  ans = min(ans, candidate)
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()))
kingaku=[]
for i in range(M):
    x_input, y_input, c_input = map(int, input().split())
    kingaku.append(a[x_input-1]+b[y_input-1]+c_input)
kingaku.append(min(a)+min(b))

print(min(kingaku))

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

key = 0
xyc_1 = xyc[0][2]

for i in range(1,m):
    if xyc_1 < xyc[i][2]:
        xyc_1 = xyc[i][2]
        key = i

x = xyc[key][0]
y = xyc[key][1]
c = xyc[key][2]

no_m = min(a)+min(b)
yes_m = a[x-1]+b[y-1]-c

print(min(no_m,yes_m))

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 i in range(M):
    if i==0:
        tmp = list(map(int, input().split()))
        checkout = a[tmp[0]-1] + b[tmp[1]-1] - tmp[2]
    else:
        tmp = list(map(int, input().split()))
        checkout = min(checkout, a[tmp[0]-1] + b[tmp[1]-1] - tmp[2])

print(checkout)

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 = int(1e18)
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: Wrong Answer

Solution code:
A, B, M = map(int, input().split(' '))
a = list(map(int, input().split(' ')))
b = list(map(int, input().split(' ')))
asum = [0]
bsum = [0]
for i in a:
    asum.append(asum[-1] + i)
for i in b:
    bsum.append(bsum[-1] + i)
ans = int(1e18)
for i in range(M):
    x, y, c = map(int, input().split(' '))
    ans = min(ans, asum[x] + bsum[y] - 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()))
x = [0]*M
y = [0]*M
c = [0]*M
for i in range(M):
    x[i], y[i], c[i] = map(int, input().split())
price = min(a) + min(b)
for j in range(M):
    if x[j] + y[j] - c[j] < price:
        price = x[j] + y[j] - c[j]
print(price)

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()))
dis = []
for i in range(M):
  dis.append(list(map(int, input().split())))
  
total = []
total.append(min(a) + min(b))

for k in range(M):
  x = dis[k][0] - 1
  y = dis[k][1] - 1
  c = dis[k][2] - 1
  discount = a[x] + b[y] - c
  total.append(discount)
  
  
print(min(total))

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()))
dis = []
for i in range(M):
  dis.append(list(map(int, input().split())))
  
total = []
for i in range(A):
  for j in range(B):
    plus = a[i] + b[j]
    total.append(plus)


for k in range(M):
  x = dis[k][0] - 1
  y = dis[k][1] - 1
  c = dis[k][2] - 1
  discount = a[x] + b[y] - c
  total.append(discount)
  
  
print(min(total))

Submission status: Wrong Answer

Solution code:
A,B,M = (int(x) for x in input().split())
a = list()
b = list()
x = list()
y = list()
c = list()
for j in input().split():
    a.append(int(j))

for j in input().split():
    b.append(int(j))
    
for i in range(M):
    tx,ty,tc = (int(j) for j in input().split())
    x.append(int(tx))
    y.append(int(ty))
    c.append(int(tc))

pat=0
mini = 200000
a.sort()
b.sort()
mini = a[0] + b[0]

#for i in range(len(a)):
#    for j in range(len(b)):
#        pat = a[i] + b[j]
#        if mini > pat:
#            mini = pat
for i in range(M):
    pat = a[x[i]-1] + b[y[i]-1] - c[i]
    if mini > pat:
        mini = pat

print(mini)

Submission status: Wrong Answer

Solution code:
a=input()
a1=input()
a2=input()
a=a.split()
a1=a1.split(" ")
a1=sorted(list(map(int,a1)))
a2=a2.split()
a2=sorted(list(map(int,a2)))
l=[]
if len(a1)==a[0] and len(a2)==a[1]:
    v=a1[0]+a2[0]
    l.append(v)
    
    for i in range(int(a[2])):
        dis=input()
        dis=dis.split()
        dis=list(map(int,dis))
        if dis[2]<=a1[dis[0]-1]+a2[dis[1]-1] :
            c=(a1[dis[0]-1]+a2[dis[1]-1])-dis[2]
            l.append(c)
    l1=sorted(set(l))
    print(l1[0])

Submission status: Wrong Answer

Solution code:
a=input()
a1=input()
a2=input()
a=a.split()
a1=a1.split(" ")
a1=sorted(list(map(float,a1)))
a2=a2.split()
a2=sorted(list(map(float,a2)))
l=[]
v=a1[0]+a2[0]
l.append(v)

for i in range(int(a[2])):
    dis=input()
    dis=dis.split()
    dis=list(map(float,dis))
    if dis[2]<=a1[int(dis[0])-1]+a2[int(dis[1])-1] :
        c=(a1[int(dis[0])-1]+a2[int(dis[1])-1])-dis[2]
        l.append(c)
l1=sorted(set(l))
if l1[0]+0.5-l[0]==0.5:
    print(int(l1[0]))
else:
    print(int(l1[0]))

Submission status: Wrong Answer

Solution code:
a=input()
a1=input()
a2=input()
a=a.split()
a=list(map(int,a))
a1=a1.split(" ")
a1=sorted(list(map(int,a1)))
a2=a2.split()
a2=sorted(list(map(int,a2)))
l=[]
if len(a1)==a[0] and len(a2)==a[1]:
    v=a1[0]+a2[0]
    l.append(v)

    for i in range(int(a[2])):
        dis=input()
        dis=dis.split()
        dis=list(map(int,dis))
        if dis[2]<=a1[dis[0]-1]+a2[dis[1]-1] :
            c=(a1[dis[0]-1]+a2[dis[1]-1])-dis[2]
            l.append(c)
    l1=sorted(set(l))
    print(l1[0])

Submission status: Wrong Answer

Solution code:
a=input()
a1=input()
a2=input()
a=a.split()
a1=a1.split(" ")
a1=sorted(list(map(int,a1)))
a2=a2.split()
a2=sorted(list(map(int,a2)))
l=[]
v=a1[0]+a2[0]
l.append(v)

for i in range(int(a[2])):
    dis=input()
    dis=dis.split()
    dis=list(map(int,dis))
    if dis[2]<=a1[dis[0]-1]+a2[dis[1]-1] and dis[0]<=len(a1) and dis[1]<=len(a2) :
        c=(a1[dis[0]-1]+a2[dis[1]-1])-dis[2]
        l.append(c)
l1=sorted(set(l))
print(l1[0])

Submission status: Wrong Answer

Solution code:
a=input()
a1=input()
a2=input()
a=a.split()
a1=a1.split(" ")
a1=sorted(list(map(int,a1)))
a2=a2.split()
a2=sorted(list(map(int,a2)))
l=[]
v=a1[0]+a2[0]
l.append(v)

for i in range(int(a[2])):
    dis=input()
    dis=dis.split()
    dis=list(map(int,dis))
    if dis[2]<=a1[dis[0]-1]+a2[dis[1]-1] and a1[dis[0]-1]<=len(a1) and a2[dis[1]-1]<=len(a2) :
        c=(a1[dis[0]-1]+a2[dis[1]-1])-dis[2]
        l.append(c)
l1=sorted(set(l))
print(l1[0])

Submission status: Wrong Answer

Solution code:
a=input()
a1=input()
a2=input()
a=a.split()
a1=a1.split(" ")
a1=sorted(list(map(int,a1)))
a2=a2.split()
a2=sorted(list(map(int,a2)))
l=[]
v=a1[0]+a2[0]
l.append(v)

for i in range(int(a[2])):
    dis=input()
    dis=dis.split()
    dis=list(map(int,dis))
    if dis[2]<=a1[dis[0]-1]+a2[dis[1]-1]:
        c=(a1[dis[0]-1]+a2[dis[1]-1])-dis[2]
        l.append(c)
l1=sorted(set(l))
print(l1[0])

Submission status: Wrong Answer

Solution code:
a=input()
a1=input()
a2=input()
a=a.split()
a1=a1.split(" ")
a1=sorted(list(map(int,a1)))
a2=a2.split()
a2=sorted(list(map(int,a2)))
l=[]
v=a1[0]+a2[0]
l.append(v)

for i in range(int(a[2])):
    dis=input()
    dis=dis.split()
    dis=list(map(int,dis))
    c=a1[dis[0]-1]+a2[dis[1]-1]-dis[2]
    l.append(c)
l1=sorted(set(l))
print(l1[0])

Submission status: Wrong Answer

Solution code:
a=input()
a1=input()
a2=input()
a=a.split()
a1=a1.split(" ")
a1=sorted(list(map(int,a1)))
a2=a2.split()
a2=sorted(list(map(int,a2)))
l=[]
v=int(a1[0])+int(a2[0])
l.append(v)

for i in range(int(a[2])):
    dis=input()
    dis=dis.split()
    c=int(a1[int(dis[0])-1])+int(a2[int(dis[1])-1])-int(dis[2])
    l.append(c)
l1=sorted(set(l))
print(l1[0])

Submission status: Wrong Answer

Solution code:
a=input()
a1=input()
a2=input()
a=a.split()
a1=a1.split(" ")
a1=sorted(list(map(int,a1)))
a2=a2.split()
a1=sorted(list(map(int,a1)))
l=[]
v=int(a1[0])+int(a2[0])
l.append(v)

for i in range(int(a[2])):
    dis=input()
    dis=dis.split()
    c=int(a1[int(dis[0])-1])+int(a2[int(dis[1])-1])-int(dis[2])
    l.append(c)
l1=sorted(set(l))
print(l1[0])

Submission status: Wrong Answer

Solution code:
a=input()
a1=input()
a2=input()
a=a.split()
a1=sorted(a1.split(" "))
a2=sorted(a2.split())
l=[]
v=int(a1[0])+int(a2[0])
l.append(v)

for i in range(int(a[2])):
    dis=input()
    dis=dis.split()
    c=int(a1[int(dis[0])-1])+int(a2[int(dis[1])-1])-int(dis[2])
    l.append(c)
l1=sorted(set(l))
print(l1[0])

Submission status: Wrong Answer

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

amin = min(A)
bmin = min(B)
smin = amin + bmin

for i in range(m):
  x, y, c= map(int, input().split())
  th = smin -c
  apmin = A[x-1]
  if apmin > th:
    pass
  else:
    bpmin = B[y-1]
    spmin = apmin + bpmin -c
    if spmin < smin:
      smin = spmin
    else:
      pass
print(smin)

Submission status: Wrong Answer

Solution code:
import cmath
import sys

INF=10**18
MOD=10**9+7
MAX=10**5+7



def main():
  A,B,M=map(int, input().split())
  a=list(map(int, input().split()))
  b=list(map(int, input().split()))
  
  ans=min(a)+min(b)
  for i in range(M):
    x,y,c=map(int, input().split())
    x-=1
    y-=1
    ans=max(ans, a[x]+b[y]-c)
  
  print(ans)
  
  
if __name__=='__main__':
    main()

Submission status: Wrong Answer

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

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

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

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

  if m[x-1][y-1]>0:
    if m[x-1][y-1]<c:
      m[x-1][y-1]=c
  else:
    m[x-1][y-1]=c
print(m)
minc=-1

for i in range(A):
  for j in range(B):
    cash=a[i]+b[j]-m[i][j]
    if minc==-1:
      minc=cash
    elif minc>0 and cash<minc:
      minc=cash

print(minc)

Submission status: Wrong Answer

Solution code:
a,b,m=map(int,input().split())
price_A=sorted(list(map(int,input().split())))
price_B=sorted(list(map(int,input().split())))
coupon=[]
for _ in range(m):
  coupon.append(list(map(int,input().split())))
ans=price_A[0]+price_B[0]
for i in range(m):
  deprice=price_A[coupon[i][0]-1]+price_B[coupon[i][1]-1]-coupon[i][2]
  if deprice < ans:
    ans = deprice
print(ans)