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:
import numpy as np
A,B,M = map(int,input().rstrip().split())
a = list(map(int,input().rstrip().split()))
b = list(map(int,input().rstrip().split()))

suml = [[0] * len(b)] * len(a)
print(suml)
for i in range(len(a)):
  for j in range(len(b)):
    suml[i][j] = a[i]+b[j]

print(suml)

sumk = [[0] * len(b)] * len(a)

for k in range(M):
  i,j,c = list(map(int,input().rstrip().split()))
  if sumk[i-1][j-1] != 0:
    sumk[i-1][j-1] = max(sumk[i-1][j-1],c)
  else:
    sumk[i-1][j-1] = c

x = np.array(suml)
y = np.array(sumk)

z = x - y

print(np.amin(z))

Submission status: Wrong Answer

Solution code:
import numpy as np

S = list(map(int,input().split()))
A = S[0]
B = S[1]
M = S[2]

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

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

sum = np.inf

#print(list1)

for i in range(0, M):
    x = list1[i][0]
    y = list1[i][1]
    c = list1[i][2]
    num = a[x-1]+b[y-1]-c
    #print(i)
    if sum > num:
        sum = num

print(sum)

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()))
coupon=[list(map(int,input().split())) for i in range(M)]
min=2*(10**5)
for j in range(M):
    p_a=coupon[j][0]
    p_b=coupon[j][1]
    p_c=coupon[j][2]
    ans=aa[p_a-1]+bb[p_b-1]-p_c
    if ans<min:
            min=ans
print(min)

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(key = lambda x: x[2], reverse=True)



if a[m[0][0]-1] + b[m[0][1]-1] - m[0][2] > min(a) + min(b):
    print(min(a) + min(b))
    exit()
elif a[m[0][0]-1] + b[m[0][1]-1] - m[0][2] < min(a) + min(b):
    print(a[m[0][0]-1] + b[m[0][1]-1] - m[0][2])
    exit()
elif a[m[0][0]-1] + b[m[0][1]-1] - m[0][2] == min(a) + min(b):
    print(min(a) + min(b))
    exit()

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



for i in range(M):
    
    c=list(map(int,input().split()))
    
    h=a[c[0]-1]+b[c[1]-1]-c[2]
    f=h
    if f > h:
        f=h
        


if d>f:
    d=f
print(d)

Submission status: Wrong Answer

Solution code:
a, b, m = map(int, input().split())
a_l = list(map(int, input().split()))
b_l = list(map(int, input().split()))
x_y_c = [list(map(int, input().split())) for _ in range(m)]

a_l_s = sorted(a_l)
b_l_s = sorted(b_l)

min_price = 10 ** 5 + 1
for i in range(m):
    price = a_l[x_y_c[i][0] - 1] + b_l[x_y_c[i][1] - 1] - x_y_c[i][2]
    if price < min_price:
        min_price = price

tmp = a_l_s[0] + b_l_s[0]
if tmp < min_price:
    print(tmp)
else:
    print(min_price)

Submission status: Wrong Answer

Solution code:
import sys

def main():
    input = sys.stdin.readline

    _, _, m = input().split()
    m = int(m)
    alist = input().split()
    blist = input().split()

    waribiki = [input().split() for _ in range(m)]
    
    res = [200000] * 200000
    count = 0
    # for a in alist:
    #   for b in blist:
    #     res[count] = int(a) + int(b)
    #     count += 1

    for i in range(m):
        res[count] = int(alist[int(waribiki[i][0])-1]) + int(blist[int(waribiki[i][1])-1]) - int(waribiki[i][2])
        count += 1
      
    print(min(res))


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(" ")]
min_a = sorted(list_a)[0]
min_b = sorted(list_b)[0]

dict_c = {}
idx = []
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
    idx.append(tuple([x, y]))

s = min_a + min_b
for (x, y) in idx:
    t = list_a[x - 1] + list_b[y - 1] - dict_c[x][y]
    if t < s:
        s = t
print(s)

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

Submission status: Wrong Answer

Solution code:
a,b,m = map(int,input().split())
A = list(input().split())
B = list(input().split())
X = []
Y = []
C = []
total = 2*10**6
for i in range(m):
    x,y,c = map(int,input().split())
    X.append(x)
    Y.append(y)
    C.append(c)
for i in range(m):
    result = int(A[int(X[int(i)])-1])+int(B[int(Y[int(i)])-1])-int(C[int(i)])
    if (total > result):
        total = result
if(int(min(A))+int(min(B))>result):
    print(result)
else:
    print(int(min(A))+int(min(B)))

Submission status: Wrong Answer

Solution code:
A, B, M = map(int, raw_input().split())
a_s = sorted(enumerate(map(int, raw_input().split())), key=lambda t: t[1])
b_s = sorted(enumerate(map(int, raw_input().split())), key=lambda t: t[1])
min_b = min([b[1] for b in b_s])
w = [[0] * B] * A
max_w = 0
for _ in xrange(M):
    x, y, c = map(int, raw_input().split())
    w[x-1][y-1] = c
    max_w = max(max_w, c)

cost = 10 ** 20
for i, a in a_s:
    if a + min_b - max_w > cost:
        break
    for j, b in b_s:
        cost = min(cost, a + b - w[i][j])
        if a + b - max_w > cost:
            break

print cost

Submission status: Wrong Answer

Solution code:
a, b, c = list(map(int,input().split()))
aa = list(map(int,input().split()))
bb = list(map(int,input().split()))
cc = [list(map(int,input().split())) for i in range(c)]
ans = 0

for i in range(c):
  ans1 = aa[cc[i][0] - 1] + bb[cc[i][1] - 1] - cc[i][2]
  if ans == 0:
    ans = ans1
  ans = min(ans,ans1)

aa.sort()
bb.sort()
ans2 = aa[0] + bb[0]
ans = min(ans, ans2)
  
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()))
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):
  ans = min(a[disc[i][0]-1] + b[disc[i][1]-1] - disc[i][2], ans)     
    
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
S.sort()
T.sort()
K = S[0]+T[0]
X = 99999999
for i in range(M):
    x,y,c = map(int,input().split())
    S = P[x-1]+Q[y-1]-c
    if S<=X:
        X = S
if X>=K:
    print(K)
else:
    print(X)

Submission status: Wrong Answer

Solution code:
a,b,m = map(int,input().split())
A = list(input().split())
B = list(input().split())
X = []
Y = []
C = []
total = 2*10**5
for i in range(m):
    x,y,c = map(int,input().split())
    X.append(x)
    Y.append(y)
    C.append(c)
for i in range(m):
    result = int(A[int(X[int(i)])-1])+int(B[int(Y[int(i)])-1])-int(C[int(i)])
    if (total > result):
        total = result
if(int(min(A))+int(min(B))>result):
    print(result)
else:
    print(int(min(A))+int(min(B)))

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

Submission status: Wrong Answer

Solution code:
a, b, m = map(int,raw_input().split())
dr = map(int,raw_input().split())
wa = map(int,raw_input().split())
xyc = [map(int,raw_input().split()) for i in range(m)]
low = 200001

for i in range(m):
    f = xyc[i][0] - 1
    d = xyc[i][1] - 1
    if low >= dr[f]+wa[d]-xyc[i][2]:
        law = dr[f]+wa[d]-xyc[i][2]

dr.sort()
wa.sort()

if law >= (dr[0] + wa[0]):
    print (dr[0] + wa[0])
else:
    print law

Submission status: Wrong Answer

Solution code:


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

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

c={}
for _ in range(M):
    xi,yi,ci=input().split()
    c[xi.zfill(6)+yi.zfill(6)]=int(ci)

ans_list=[]

for i in range(A):
    for j in range(B):
        ans=a[i]+b[i]
        if str(i+1).zfill(6)+str(j+1).zfill(6) in c.keys():
            ans-=c[str(i+1).zfill(6)+str(j+1).zfill(6)]
        ans_list.append(ans)

print(min(ans_list))

Submission status: Wrong Answer

Solution code:
a,b,m=map(int,input().split())
ak=list(map(int,input().split()))
bk=list(map(int,input().split()))
kei=[]
for i in range(m):
    x,y,c=map(int,input().split())
    pay=ak[x-1]+bk[y-1]-c
    kei.append(pay)
print(min(kei))

Submission status: Wrong Answer

Solution code:
a, b, m = map(int,raw_input().split())
dr = map(int,raw_input().split())
wa = map(int,raw_input().split())
xyc = [map(int,raw_input().split()) for i in range(m)]
low = 200001

for i in range(m):
    f = xyc[i][0] - 1
    d = xyc[i][1] - 1
    if low >= dr[f]+wa[d]-xyc[i][2]:
        law = dr[f]+wa[d]-xyc[i][2]

dr.sort()
wa.sort()

if law >= (dr + wa):
    print (dr + wa)
else:
    print law

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(key = lambda x: x[2], reverse=True)



if a[m[0][0]-1] + b[m[0][1]-1] - m[0][2] > min(a) + min(b):
    ans = min(a) + min(b)
    print(ans)
    exit()
elif a[m[0][0]-1] + b[m[0][1]-1] - m[0][2] <= min(a) + min(b):
    ans = a[m[0][0]-1] + b[m[0][1]-1] - m[0][2]
    print(ans)
    exit()

print(min(a) + min(b))

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):
  ans = min(a[disc[i][0]-1] + b[disc[i][1]-1] - disc[i][2], ans)     
    
print(a,b,ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import numpy as np


def solve(*args: str) -> str:
    a, b, m = map(int, args[0].split())
    A = list(map(int, args[1].split()))
    B = list(map(int, args[2].split()))

    XYC = {}
    for x, y, c in map(str.split, args[3:]):
        key = (int(x)-1, int(y)-1)
        XYC[key] = max(XYC.get(key, 0), int(c))

    X = np.argsort(A)
    Y = np.argsort(B)
    ret = A[X[0]]+B[Y[0]]
    for x in X:
        for y in Y:
            if ret < A[x]+B[y]:
                break
            ret = min(ret, A[x]+B[y]-XYC.get((x, y), 0))

    return str(ret)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))

Submission status: Wrong Answer

Solution code:
abm = input('')
a = int(abm.split(' ')[0])
b = int(abm.split(' ')[1])
m = int(abm.split(' ')[2])
clist = []
dlist = []
wdic = {}
cin = input('')
din = input('')
for i in range(0,a):
  clist.append(int(cin.split(' ')[i]))
for i in range(0,b):
  dlist.append(int(din.split(' ')[i]))
for i in range(0,m):
  win = input('')
  wc = win.split(' ')[0]
  wd = win.split(' ')[1]
  wkey = wc + "-" + wd
  wp = int(win.split(' ')[2])
  if wkey in wdic.keys():
    if wp > wdic[wkey]:
      wdic[wkey] = wp
  else:
    wdic[wkey] = wp

min_price = -1

for i in range(0,a):
  for j in range(0,b):
    total = clist[i] + dlist[j]
    if min_price == -1:
      min_price = total
    elif total < min_price:
      min_price = total      
    wkey = str(i+1) + "-" + str(j+1)
    if wkey in wdic.keys():
        w = wdic[wkey]
        total = clist[i] + dlist[j] - wp
        if total < min_price:
            min_price = total

print(min_price)

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()]
c = {}
for i in range(M):
    x, y, c2 = map(int, input().split())
    c[(x, y)] = c2
    
min = 2000000    
for i in range(A):
    for j in range(B):
        if (i+1, j+1) in c:
            value = a[i] + b[j] - c[(i+1, j+1)]
        else: 
            value = a[i] + b[j]
        if min > value:
            min = value

print(min)

Submission status: Wrong Answer

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

cost = 10 ** 20
for i, a in a_s:
    for j, b in b_s:
        cost = min(cost, a + b - w[i][j])
        if a + b - max_w > cost:
            break
    else:
        continue
    break

print cost

Submission status: Wrong Answer

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

aa = list(map(int, input().split()))
bb = list(map(int, input().split()))

xyc = [[0]*3]*m

for i in range(m):
    xyc[i][0],xyc[i][1],xyc[i][2] = (int(x) for x in input().split())

ma = min(aa)
mb = min(bb)
ans = ma+mb

for i in range(m):
    sum = aa[xyc[i][0] -1] + bb[xyc[i][1] -1] - xyc[i][2]
    if ans > sum:
        ans = sum

print(ans)

Submission status: Wrong Answer

Solution code:
na,nb,M=map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = [[0 for i in range(3)] for j in range(M)]
#C = [[0]*3]*M
s=min(A)+min(B)
t=0

#print(A)
#print(B)

for i in range(M):
	C[i][0],C[i][1],C[i][2] = map(int, input().split())

#print(C)

for j in range(M):
	print(j)
	t=A[C[j][0]-1]+B[C[j][1]-1]-C[j][2]
	if t<s:
		s=t

print(s)

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()))
buf=min(A)+min(B)
for i in range(m):
    x,y,c=map(int, input().split())
    cp=A[x-1]+B[y-1]-c
    if buf>=cp:
        buf==cp
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()))
xyc = [list(map(int,input().split())) for _ in range(M)]
pay = 0
min_pay = 0
for i in range(M):
  pay = a[xyc[i][0]-1] + b[xyc[i][1]-1] - xyc[i][2]
  if i == 0:
    min_pay = pay
  min_pay = min(min_pay,pay)
print(min_pay)

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

e=list(map(int,input().split()))
c=e
for i in range(M-1):
    e=c
    c=list(map(int,input().split()))
    if c[2]>e[2]:
        e=c
f=a[e[0]-1]+b[e[1]-1]-e[2]
if d>f:
    d=f
print(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()))
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 and (a[x-1]+b[y-1]) - c > 0:
        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, c = list(map(int,input().split()))
aa = list(map(int,input().split()))
bb = list(map(int,input().split()))
cc = [list(map(int,input().split())) for i in range(c)]

d = aa.sort()
e = bb.sort()
ans1 = aa[0] + bb[0]

for i in range(c):
  ans2 = aa[cc[i][0] - 1] + bb[cc[i][1] - 1] - cc[i][2]
  ans = min(ans1,ans2)
  
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 for _ in range(m)]
y = [0 for _ in range(m)]
c = [0 for _ in range(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(A):
    if(a[i] > ans):
        continue
    for j in range(B):
        if((a[i] + b[j]) > ans):
            continue
        for k in range(m):
            if(i+1 == x[k] and j+1 == y[k]):
                price = a[i] + b[j] - c[k]
            else:
                price = a[i] + b[j]
            ans = min(ans,price)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

a, b, m = MAP()
A = LIST()
B = LIST()
A.sort()
B.sort()
# print(A)
# print(B)
L = [LIST() for i in range(m)]

ans = A[0] + B[0]
for x, y, c in L:
    # print(x, y, c)
    v = A[x-1] + B[y-1] - c
    if  ans > v:
        ans = v
print(ans)


# exit()


# D = [[0] * b for i in range(a)]
# for x,y,c in L:
#     D[x-1][y-1] = max(D[x-1][y-1], c)
# ans = INF
# C = [[0] * b for i in range(a)]
# for i in range(a):
#     for j in range(b):
#         ans = min(A[i] + B[j] - D[i][j], ans)
        
# print(ans)

# # exit()

# # for x, y, c in L:
# #     C[x-1][y-1] = min(C[x-1][y-1], C[x-1][y-1]-c)

# # print(min(C))


# # #     ans.append(A[x-1] + B[y-1] - c)
# # # print(min(ans))



# # exit()
# # s = input()
# # m= "hi"
# # # for i in range():
# # l = len(s) // 2
# # if l * m == s:
# #     print("Yes")
# # else:
# #     print("No")

# # # if s // 2

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

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

w = {}
for i in range(M):
    x[i], y[i], c[i] = [int(n) for n in input().split()]
    w[(x[i], y[i])] = c[i]

m = 200000

for i in range(A):
    for j in range(B):
        p = a[i] + b[j]
        if (i + 1, j + 1) in w:
            p -= w[(i + 1, j + 1)]
        if p < m:
            m = p

print(m)

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(aa):
  price1 = a[i] + min(b)
  price.append(price1)
  if i <= m-1:
    price.append(a[x[i] - 1] + b[y[i] - 1] - c[i])
  
  
  
print(min(price))

Submission status: Wrong Answer

Solution code:
refN, renN, disN = map(int, input().split())

ref = list(map(int,input().split()))
ren = list(map(int,input().split()))

dis = [input().split() for _ in range(disN)]
 
minCost = 0

for kk in range(disN):
    cost = ref[int(dis[kk][0])-1] + ren[int(dis[kk][1])-1] - int(dis[kk][2])
    if minCost == 0 or cost < minCost:
        minCost = cost
 
ref.sort()
ren.sort()

cost = ren[0] + ref[0]
if cost < minCost:
    minCost = cost

print(minCost)

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(" ")]
list_c = [[0 for j in range(B + 1)] for i in range(A + 1)]
for i in range(M):
    x, y, c = [int(x) for x in sys.stdin.readline().strip().split(" ")]
    list_c[x][y] = c

s = 1e5
for i, a in enumerate(list_a):
    for j, b in enumerate(list_b):
        t = a + b - list_c[i + 1][j + 1]
        if s > t:
            s = t
print(s)

Submission status: Wrong Answer

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

if min(a) + min(b) > a[d[max_i][0] - 1] + b[d[max_i][1] - 1] - d[max_i][2]:
  print(a[d[max_i][0] - 1] + b[d[max_i][1] - 1] - d[max_i][2])
else:
  print(min(a) + min(b))

Submission status: Wrong Answer

Solution code:
import sys

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

prices_A=list(map(int,input().split()))
prices_B=list(map(int,input().split()))

dc = dict()
for i in range(M):
    (x,y,c)=map(int,input().split())
    idx="{} {}".format(x,y)
    dc[idx]=c

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

min_p = prices_A[0] + prices_B[0]
for i in range(A):
    x=i+1
    for j in range(B):
        y=j+1
        c=0
        idx = "{} {}".format(x,y)
        if idx in dc:
            c=dc[idx]
        p = prices_A[i]+prices_B[j]-c

        if p < min_p:
            min_p=p
print(min_p)

Submission status: Wrong Answer

Solution code:
s = input()
s_len = len(s)
if s_len % 2:
  print("No")
else:
  prev = 0
  count = 0
  for i in range(1, (s_len//2)+1):
    if s[prev:i*2] != "hi":
      print("No")
      break
    else:
      count += 1
      prev = i * 2
  if count == s_len // 2:
    print("Yes")

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 = min(a)+min(b)
    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:
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=float("INF")
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
        price_min=price if price_min > price else price
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()))
minA = a[0]
for reizou in a[1:]:
    if reizou < minA:
        minA = reizou
minB = b[0]
for renzi in b:
    if renzi < minB:
        minB = renzi
min = minA + minB
for i in range(M):
    x,y,c = map(int,input().split())
    sum = a[x-1] + b[y-1] - c
    if sum < min:
        min = sum

print(sum)

Submission status: Wrong Answer

Solution code:
a, b, m = map(int, input().split())
a_l = list(map(int, input().split()))
b_l = list(map(int, input().split()))
x_y_c = [list(map(int, input().split())) for _ in range(m)]

a_l_s = sorted(a_l)
b_l_s = sorted(b_l)

min_price = 10 ** 5
for i in range(m):
    price = a_l[x_y_c[i][0] - 1] + b_l[x_y_c[i][1] - 1] - x_y_c[i][2]
    if price < min_price:
        min_price = price

tmp = a_l_s[0] + b_l_s[0]
if tmp < min_price:
    print(tmp)
else:
    print(min_price)

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(" ")]
C = []

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

print(a)

m = 1000000

for i in a:
  for j in b:
    cost = i + j
    if m >= cost:
      m = cost

for c in C:
  cost = a[c[0] - 1] + b[c[1] - 1] - c[2]
  if m >= cost:
    m = cost

print(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()))
ab = []
for i in range(min(A,B)):
  ab.append([a[i], b[i]])
ab.sort(key=lambda x: x[0])

ans = 10**5+1
for i in range(m):
  x, y, c = map(int, input().split())
  if m <= min(A, B):
    ans = min(ans, a[x-1] + b[y-1] - c, ab[i][0] + ab[i][1])
  else: 
    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()))
tickets=list()
for i in range(m):
    tickets.append(list(map(int,input().split())))

price_min=float("INF")
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 = []
for i in range(min(A,B)):
  ab.append([a[i], b[i]])
ab.sort(key=lambda x: x[0])

ans = 10**5+1
for i in range(m):
  x, y, c = map(int, input().split())
  if m <= min(A, B):
    ans = min(ans, ab[i][0] + ab[i][1])
  ans = min(ans, a[x-1] + b[y-1] - c)
  
print(ans)

Submission status: Wrong Answer

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

a, b, m = MAP()
A = LIST()
B = LIST()
A.sort()
B.sort()
L = [LIST() for i in range(m)]

m = A[0] + B[0]
for x, y, c in L:
    v =A[x-1] + B[y-1] - c
    if  v <= m:
        m = v
print(m)


# exit()


# D = [[0] * b for i in range(a)]
# for x,y,c in L:
#     D[x-1][y-1] = max(D[x-1][y-1], c)
# ans = INF
# C = [[0] * b for i in range(a)]
# for i in range(a):
#     for j in range(b):
#         ans = min(A[i] + B[j] - D[i][j], ans)
        
# print(ans)

# # exit()

# # for x, y, c in L:
# #     C[x-1][y-1] = min(C[x-1][y-1], C[x-1][y-1]-c)

# # print(min(C))


# # #     ans.append(A[x-1] + B[y-1] - c)
# # # print(min(ans))



# # exit()
# # s = input()
# # m= "hi"
# # # for i in range():
# # l = len(s) // 2
# # if l * m == s:
# #     print("Yes")
# # else:
# #     print("No")

# # # if s // 2

Submission status: Wrong Answer

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

if min(a) + min(b) > a[d[max_i][0] - 1] + b[d[max_i][0] - 1] - d[max_i][2]:
  print(a[d[max_i][0] - 1] + b[d[max_i][0] - 1] - d[max_i][2])
else:
  print(min(a) + min(b))

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)
elif ans > min(a):
    ans = min(a)
else:
    ans = min(b)

print(ans)

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()]
    if waribiki[y-1][x-1] !=0:
        waribiki[y-1][x-1] = min(c,waribiki[y-1][x-1])
    else:
        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]
        if p<ans:
            ans =p

print(ans)

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline


def main():
    a, b, m = map(int, input().split())
    refrigerators = list(map(int, input().split()))
    microwaves = list(map(int, input().split()))
    tickets = [list(map(int, input().split())) for _ in range(m)]
    tickets_map = {}
    for x, y, c in tickets:
        key = '{0}:{1}'.format((x - 1), (y - 1))
        tickets_map[key] = c

    ret = 99999999999999
    for x in range(a):
        for y in range(b):
            key = '{0}:{1}'.format(x, y)
            d = tickets_map.get(key, 0)
            p = refrigerators[x] + microwaves[y] - d
            ret = min(ret, p)
    print(ret)


if __name__ == '__main__':
    main()