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 = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]

m = []

for i in range(M):
    x, y, z = map(int, input().split())
    m.append([x, y, z])

m.sort(reverse = True,key = lambda x: x[2])


ans = 10000000000
if a[m[0][0]-1] + b[m[0][1]-1] - m[0][2] >= min(a) + min(b):
    ans = min(a) + min(b)
else:
    ans = a[m[0][0]-1] + b[m[0][1]-1] - m[0][2]

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

Submission status: Wrong Answer

Solution code:
aa, bb, m = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
x = []
y = []
c = []
for i in range(m):
  x1, y1, c1 = list(map(int,input().split()))
  x.append(x1)
  y.append(y1)
  c.append(c1)

price = []
  
for i in range(m):
  price.append(a[x[i] - 1] + b[y[i] - 1] - c[i])
  
print(min(price))

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]"):
    a = sorted(a)
    b = sorted(b)
    result = a[0] + b[0]
    for i in range(M):
        result = min(result,a[x[i]-1]+b[y[i]-1]-c[i])
    print(result)
    return


# Generated by 1.1.6 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=[int(x) for x in input().split()]

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

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

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

ans = 1000000007
for i in range(A):
    for j in range(B):
        p = a[i]+b[j]-waribiki[j][i]
        if p<ans:
            ans =p

print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
A, B, M = map(int, input().split())
# print("A:", A, "B:", B, "M:", M)
a = list(map(int, input().split()))
# print("a:", a)
b = list(map(int, input().split()))
# print("b:", b)
z = [list(map(int, input().split())) for _ in range(M)]
num1 = a[0] + b[0]
for i in range(M):
    # print("z[i]:", z[i])
    x, y, c = z[i]
    # print("x:", x, "y:", y, "c:", c)
    num = a[x - 1] + b[y - 1] - c
    # print(num)
    if num < num1:
        num1 = num
print(num1)

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()))
tickets=list()
for i in range(m):
    tickets.append(list(map(int,input().split())))

price_min=10**5*2
for ticket in tickets:
    price = A[ticket[0]-1] + B[ticket[1]-1] - ticket[2]
    price_min = price if price_min>price else price_min

# 割引券を使わない場合
for _a in A:
    for _b in B:
        price=_a + _b
        if price_min > price: price_min=price
        else: break
print(price_min)

Submission status: Wrong Answer

Solution code:
A,B,M = map(int,input().split())
P = list(map(int,input().split()))
Q = list(map(int,input().split()))
S = P
T = Q
S.sort()
T.sort()
minimum = (S[0]+T[0])
for i in range(M):
    x,y,c = map(int,input().split())
    S = P[x-1]+Q[y-1]-c
    if S<minimum:
        minimum = S
print(minimum)

Submission status: Wrong Answer

Solution code:
import sys
A, B, M = map(int, input().split())
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
# discounts = list(list(map(int, input().split())) for _ in )

prices = []
for i in range(len(a_list)):
    b_line = []
    for j in range(len(b_list)):
        b_line.append(a_list[i] + b_list[j])
    prices.append(b_line)

discounts = []
for i in range(len(a_list)):
    b_line = []
    for j in range(len(b_list)):
        b_line.append(0)
    discounts.append(b_line)

for discount in sys.stdin:
    x, y, c = map(int, discount.split())
    if discounts[x - 1][y - 1] > -c:
        discounts[x - 1][y - 1] = c

min = -1
for i in range(len(a_list)):
    for j in range(len(b_list)):
        price = prices[i][j] - discounts[i][j]
        if price < min or min == -1:
            min = price
print(min)

Submission status: Wrong Answer

Solution code:
#B
a,b,m=map(int,input().split())
al=list(map(int,input().split()))
bl=list(map(int,input().split()))
amin=min(al)
bmin=min(bl)
minp=amin+bmin
print(amin,bmin)
for i in range(m):
    num=list(map(int,input().split()))
    price=al[num[0]-1]+bl[num[1]-1]-num[2]
    minp=min(price,minp)
print(minp)

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]"):
    a = sorted(a)
    b = sorted(b)
    result = a[0] + b[0]
    for i in range(M):
        result = min(result,a[x[i]-1]+b[y[i]-1]-c[i])
    print(max(0,result))
    return


# Generated by 1.1.6 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:
import sys

A, B, M = [int(x) for x in sys.stdin.readline().strip().split(" ")]
list_a = [int(x) for x in sys.stdin.readline().strip().split(" ")]
list_b = [int(x) for x in sys.stdin.readline().strip().split(" ")]
dict_c = {}
for i in range(M):
    x, y, c = [int(x) for x in sys.stdin.readline().strip().split(" ")]
    if x not in dict_c:
        dict_c[x] = {}
    dict_c[x][y] = c

s = 1e5
for i, a in enumerate(list_a):
    for j, b in enumerate(list_b):
        t = a + b - dict_c.get(i + 1, {}).get(j + 1, 0)
        if s > t:
            s = t
print(s)

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

m = []

for i in range(M):
    x, y, z = map(int, input().split())
    m.append([x, y, z])

m.sort(reverse = True,key = lambda x: x[2])


ans = 100000
if a[m[0][0]-1] + b[m[0][1]-1] - m[0][2] >= min(a) + min(b):
    ans = min(a) + min(b)
else:
    ans = a[m[0][0]-1] + b[m[0][1]-1] - m[0][2]

print(ans)

Submission status: Wrong Answer

Solution code:
# Author: cr4zjh0bp
# Created: Sun Mar  8 12:19:06 UTC 2020
import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni = lambda: int(ns())
nin = lambda y: [ni() for _ in range(y)]
na = lambda: list(map(int, stdin.readline().split()))
nan = lambda y: [na() for _ in range(y)]
nf = lambda: float(ns())
nfn = lambda y: [nf() for _ in range(y)]
nfa = lambda: list(map(float, stdin.readline().split()))
nfan = lambda y: [nfa() for _ in range(y)]
ns = lambda: stdin.readline().rstrip()
nsn = lambda y: [ns() for _ in range(y)]
ncl = lambda y: [list(ns()) for _ in range(y)]
nas = lambda: stdin.readline().split()

A, B, M = na()
a = na()
b = na()
xyc = nan(M)
ans = inf
for i in range(M):
    x, y, c = xyc[i]
    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())
P = list(map(int,input().split()))
Q = list(map(int,input().split()))
S = P
T = Q
K = 0
S.sort()
T.sort()
minimum = (S[0]+T[0])
for i in range(M):
    x,y,c = map(int,input().split())
    S = P[x-1]+Q[y-1]-c
    if S<minimum:
        minimum = S
if K < minimum :
    print(K)
else:
    print(minimum)

Submission status: Wrong Answer

Solution code:
a,b,m=map(int,input().split())
*a,=map(int,input().split())
*b,=map(int,input().split())
mi=10**9
for i in range(m):
    x,y,c=map(int,input().split())
    if len(a)<=x and len(b)<=y:
        res=a[x-1]+b[y-1]-c
        mi=min(mi,res)
l=min(a)+min(b)
print(min(mi,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()))
tickets=list()
for i in range(m):
    tickets.append(list(map(int,input().split())))

price_min=10**5
for ticket in tickets:
    price = A[ticket[0]-1] + B[ticket[1]-1] - ticket[2]
    price_min = price if price_min>price else price_min

# 割引券を使わない場合
for _a in A:
    for _b in B:
        price=_a + _b
        if price_min > price: price_min=price
        else: break
print(price_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()))
ab = [a+b for a, b in zip(a, b)]
ans = []
for i in ab:
    ans.append(i)

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

print(min(ans))

Submission status: Wrong Answer

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

min_cost = 10 ** 6

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

Submission status: Wrong Answer

Solution code:
A,B,M = map(int,input().split())
P = list(map(int,input().split()))
Q = list(map(int,input().split()))
S = P
T = Q
minimum = 99999999
K = 0
S.sort()
T.sort()
K = (S[0]+T[0])
for i in range(M):
    x,y,c = map(int,input().split())
    S = P[x-1]+Q[y-1]-c
    if S<minimum:
        minimum = S
if K < minimum :
    print(K)
else:
    print(minimum)

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

m = []

for i in range(M):
    x, y, z = map(int, input().split())
    m.append([x, y, z])

m.sort(reverse = True,key = lambda x: x[2])


ans = 100000
if a[m[0][0]-1] + b[m[0][1]-1] - m[0][2] > min(a) + min(b):
    ans = min(a) + min(b)
else:
    ans = a[m[0][0]-1] + b[m[0][1]-1] - m[0][2]

print(ans)

Submission status: Wrong Answer

Solution code:
A, B, M = map(int, input().split())
a_price = list(map(int, input().split()))
b_price = list(map(int, input().split()))
coupon = [list(map(int, input().split())) for i in range(M)]
min = a_price[0] + b_price[0]
for cpn in coupon:
    idx_a = cpn[0]-1
    idx_b = cpn[1]-1
    total = a_price[idx_a] + b_price[idx_b] - cpn[2]
    if min > total:
        min = total

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

x = [0] * M
y = [0] * M
c = [0] * M

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

print(ans)

Submission status: Wrong Answer

Solution code:
A, B, M = map(int, input().split())
ref = list(map(int, input().split()))
mic = list(map(int, input().split()))
coupons = [ list(map(int, input().split())) for i in range(M)]
ans = min(ref) + min(mic)

for i in coupons:
  print(i)
  price = ref[i[0]-1] + mic[i[1]-1] - i[2]
  if price < ans:
    ans = price

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
Y = 0
C = 0
Min = min(a) + min(b)

for _ in range(M):
    x, y, c = map(int, input().split())
    if c >= C:
        X = x - 1 
        Y = y - 1
        C = c

res = (a[X] + b[Y]) - C
if Min < res:
    print(Min)
    exit()
print(res)

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

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

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()))
L=[list(map(int,input().split())) for i in range(M)]
x=[]
y=[]
c=[]
for i in range(M):
    x.append(L[i][0])
    y.append(L[i][1])
    c.append(L[i][2])
La=min(a)
Lb=min(b)
for i in range(M):
    X=x[i]-1
    Y=y[i]-1
    han=a[X]+b[Y]-c[i]
    ans=min(han,La+Lb)
print(ans)

Submission status: Wrong Answer

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

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

al = list(map(int, al))
bl = list(map(int, bl))

al = sorted(al)
bl = sorted(bl)

tmp = al[0] + bl[0]

comp = 0
fp = tmp
for i in ml:
  comp = al[i[0]-1] + bl[i[1]-1] - i[2]
  if comp < fp:
    fp = comp

print(fp)

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()))
coupon = {}
for i in range(M):
  x,y,c = map(int,input().split())
  coupon[(x,y)] = c
values = []
for i, p in enumerate(a):
  for j, q in enumerate(b):
    if (i+1,j+1) in coupon:
      values.append(p+q-coupon[(i+1,j+1)])
    else:
      values.append(p+q)
print(min(values))

Submission status: Wrong Answer

Solution code:
s = input()
if s.replace('hi','') == '':
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
A,B,M = map(int,input().split())
P = list(map(int,input().split()))
Q = list(map(int,input().split()))
S = P
T = Q
minimum = 99999999
K = 0
S.sort()
P.sort()
K = (S[0]+P[0])
for i in range(M):
    x,y,c = map(int,input().split())
    S = P[x-1]+Q[y-1]-c
    if S<minimum:
        minimum = S
if K < minimum :
    print(K)
else:
    print(minimum)

Submission status: Wrong Answer

Solution code:
import numpy as np
A, B, M = map(int,input().split())
a = np.array([int(num) for num in input().split()])
a_min = np.min(a)

b = np.array([int(num) for num in input().split()])
b_min = np.min(b)
total_min= a_min + b_min

for i in range(0, M):
    x, y, c = map(int,input().split())
    min_can = a[x-1] + b[y-1] -c
    if total_min > min_can:
        taotal_min = min_can
print(total_min)

Submission status: Wrong Answer

Solution code:

if __name__ == "__main__":
    S = input()
    if len(S) % 2 == 0:
        for i in range(0, len(S), 2):
            if S[i] == "h" and S[i+1] == "i":
                ret = "Yes"
            else:
                ret = "No"
                break
    else:
        ret = "No"
    print(ret)

Submission status: Wrong Answer

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

tmp=99999999

for i in range(m):
    x,y,c=[int(i) for i in input().split()]
    cost=al[x-1]+bl[y-1]-c
    #各クーポンを使った時の金額
    tmp=min(tmp,cost)

k=(min(al)+min(bl))
#割引券を使わなかった時の最小値
print(min(k,cost))

Submission status: Wrong Answer

Solution code:
A, B, M = [int(i) for i in input().split()]
a_i = [int(i) for i in input().split()]
b_i = [int(i) for i in input().split()]
m_i = [[int(j) for j in input().split()] for i in range(M)]


min_v = 10^5
for m in m_i:
    v = a_i[m[0]-1] + b_i[m[1]-1] - m[2]

    if v < min_v:
        min_v = v

min_pair = min(a_i) + min(b_i)

if min_pair < min_v:
    min_v = min_pair

print(min_v)

Submission status: Wrong Answer

Solution code:
def main():
    A,B,M = map(int,input().split())
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))
    c = [[-1 for i in range(2)] for j in range(A)]


    for i in range(M):
        x,y,cc = map(int,input().split())
        c[x-1] = [y-1, cc]
    a_min = min(a)
    b_min = min(b)
    ans = 10 ** 6
    for i, a_i in enumerate(a):
        tmp_1 = a_i + b_min
        tmp_2 = 10**6
        if c[i][0] != -1:
             tmp_2 = a_i + b[c[i][0]] - c[i][1]
        ans = min(ans,tmp_1,tmp_2)
    print(ans)
if __name__=='__main__':
    main()

Submission status: Wrong Answer

Solution code:
def solve():
    # N = int(input())
    # N, M = map(int, input().split())
    # A = list(map(int, input().split()))
    S = input()
    # if 'hi' in S:
    #     print('Yes')
    # else:
    #     print('No')

    for i in range(len(S)):
        if i % 2 == 0 and S[i] != 'h':
            print('No')
            break
        if i % 2 != 0 and S[i] != 'i':
            print('No')
            break
    else:
        if S[-1] == 'i':
            print('Yes')
        else:
            print('No')





if __name__ == '__main__':
    solve()

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from operator import itemgetter

A, B, M = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
d = [[int(i) for i in input().split()] for _ in range(M)]

d.sort(key=itemgetter(2), reverse=True)
ans = A[d[0][0]-1] + B[d[0][0]-1] - d[0][2]

A.sort()
B.sort()

ans = min(ans, A[0] + B[0])
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 = 200000

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

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

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

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

min_comb = min(a)+min(b)

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

Submission status: Wrong Answer

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

from collections import defaultdict

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

MINB = min(b)

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

a.sort(); b.sort()

ans = float("inf")
for i in range(A):
    tmp = a[i] + MINB
    for y,c in wari[i]:
        tmp = min(tmp, a[i] + b[y] - c)
    ans = min(ans, tmp)

print(ans)

Submission status: Wrong Answer

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

tmp=0

for i in range(m):
    x,y,c=[int(i) for i in input().split()]
    cost=al[x-1]+bl[y-1]-c
    #各クーポンを使った時の金額
    tmp=min(tmp,cost)

k=(min(al)+min(bl))
#割引券を使わなかった時の最小値
print(min(k,cost))

Submission status: Wrong Answer

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

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

a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
m = [list(map(int, input().split())) for _ in range(M)]

ans = 0
for x in m:
    if not ans:
        ans = a[x[0] - 1] + b[x[1] - 1] - x[2]
    else:
        ans = min(ans, a[x[0] - 1] + b[x[1] - 1] - x[2])

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

Submission status: Wrong Answer

Solution code:
import numpy as np
A, B, M = map(int,input().split())
a = np.array([int(num) for num in input().split()])
a_min = np.min(a)

b = np.array([int(num) for num in input().split()])
b_min = np.min(b)
total_min= a_min + b_min
for i in range(0, M):
    x, y, c = map(int,input().split())
    min_can = a[x-1] + b[y-1] -c
    if total_min > min_can:
        taotal_min = min_can
print(min_can)

Submission status: Wrong Answer

Solution code:
def main():
    a, b, m = map(int, input().split())
    a_list = list(map(int, input().split()))
    b_list = list(map(int, input().split()))
    waribiki = []
    waribiki_result = 0

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

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


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

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

x = {}
for _ in range(m):
    _list = list(map(int, input().split()))
    x[(_list[0], _list[1])] = _list[2]

ans = float('inf')

for i in range(len(a)):
    for j in range(len(b)):
        if (i+1, j+1) in x:
            waribiki = x[(i+1, j+1)]
        else:
            waribiki = 0

        kaikei = a[i] + b[j] - waribiki
        if kaikei < ans:
            ans = kaikei

print(ans)

Submission status: Wrong Answer

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

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

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

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

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

print(answer)

Submission status: Wrong Answer

Solution code:
import sys

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


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

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

a = load_list()
b = load_list()

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

print(a, b, coupon)


minv = a[0] + b[0]
for i in range(0, A):
    for j in range(i, B):
        v = a[i] + b[i]
        if (i, j) in coupon:
            v -= coupon[(i,j)]
        minv = min(minv, v)
print(minv)

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

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

xyc.sort()

print(min(min(a)+min(b), a[xyc[0][1]] + b[xyc[0][2]] + xyc[0][0]))

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()))
k = []
for i in range(m):
    t1,t2,t3 = map(int, input().split())
    dis = As[t1-1] + Bs[t2-1] - t3
    k.append(dis)
print(min(k))

Submission status: Wrong Answer

Solution code:
A, B, M = map(int, raw_input().split())
a_s = map(int, raw_input().split())
b_s = map(int, raw_input().split())
w = [[0] * B] * A
for _ in xrange(M):
    x, y, c = map(int, raw_input().split())
    w[x-1][y-1] = c

cost = 10 ** 20
for i, a in enumerate(a_s):
    for j, b in enumerate(b_s):
        cost = min(cost, a + b - w[i][j])

print cost

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

price = min(A)+min(B)
for x,y,c in xyc:
    k = A[x-1] + B[y-1] - c 
    print(k)
    if k < price:
        price = k
        
print(price)

Submission status: Wrong Answer

Solution code:
def main():
    A, B, M = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    xyc = [tuple(map(int, input().split())) for _ in range(M)]

    xyc = {(x, y): c for x, y, c in xyc}

    ans = a[0] + b[0]
    for i, ai in enumerate(a):
        for j, bj in enumerate(b):
            if (i + 1, j + 1) in xyc:
                ans = min(ans, ai + bj - xyc[(i + 1, j + 1)])
            else:
                ans = min(ans, ai + bj)

    print(ans)


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()))
ans = float('inf')
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())
P = list(map(int,input().split()))
Q = list(map(int,input().split()))
S = P
T = Q
minimum = 99999999
K = 0
S.sort()
P.sort()
K = (S[0]+P[0])
for i in range(M):
    x,y,c = map(int,input().split())
    S = P[x-1]+Q[y-1]-c
    if S<minimum:
        minimum = S
if minimum<K:
    print(minimum)
else:
    print(K)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# 日立コン
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)

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

Alist = list(map(int, readline().split()))
Blist = list(map(int, readline().split()))

answer = 10 ** 7
for a, b in zip(Alist, Blist):
    tmp = a + b
    if tmp < answer:
        answer = tmp

for _ in range(0, M):
    x, y, c = map(int, readline().split())
    tmp = Alist[x-1] + Blist[y-1] - c
    if answer is None:
        answer = tmp
        continue
    if tmp < answer:
        answer = tmp
        continue
print(answer)

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

ans = 100000000

for i in range(m):
    x,y,c = xyc[i]
    cost = A[x-1] + B[y-1] - c
    if ans > cost:
        ans = cost

if cost > min(A) + min(B):
    ans = min(A) + min(B)

print(ans)

Submission status: Wrong Answer

Solution code:
a,b,m=map(int,input().split())
fri=list(map(int,input().split()))
mic=list(map(int,input().split()))
wari=[list(map(int,input().split())) for i in range(m)]
fri.sort()
mic.sort()
mi=fri[0]+mic[0]
for i in range(m):
    if fri[wari[i][0]-1]+mic[wari[i][1]-1]-wari[i][2]<mi:
        mi=fri[wari[i][0]-1]+mic[wari[i][1]-1]-wari[i][2]
print(mi)

Submission status: Wrong Answer

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

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

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

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

ans = 1000000007
for i in range(A):
    for j in range(B):
        p = a[i]+b[j]-waribiki[j][i]
        ans = min(p,ans)

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