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 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 ** 5) + 1
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:
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())
    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(0, 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:
# -*- coding: utf-8 -*-

a, b, m = map(int, input().split())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
res = A[0] + B[0]
for j in range(m):
    x, y, c = map(int, input().split())
    summ = A[x-1] + B[y-1] - c
    if summ < res:
        res = summ

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

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

Submission status: Wrong Answer

Solution code:
a,b,m=map(int,input().split())
als=list(map(int,input().split()))
bls=list(map(int,input().split()))
mls=[list(map(int,input().split())) for i in range(m)]

als.sort()
bls.sort()

ans=als[0]+bls[0]
for i in mls:
    aidx = i[0]-1
    bidx = i[1]-1
    cost = als[aidx]+bls[bidx]-i[2]
    if cost < ans:
        ans = cost
print(ans)

Submission status: Wrong Answer

Solution code:
S=input()
if(S=="hi"):
  print("Yes")
elif(S=="hihi"):
  print("Yes")
elif(S=="hihihi"):
  print("Yes")
elif(S=="hihihihi"):
  print("Yes")
elif(S=="hihihihihi"):
  print("Yes")
elif(S=="hihihihihihi"):
  print("Yes")
elif(S=="hihihihihihihi"):
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

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

a_n = list(map(int, input().split(' ')))
b_n = list(map(int, input().split(' ')))

m_n = []
for i in range(M):
    m_n.append(list(map(int, input().split(' '))))

# print(A, B, M)
# print(a_n)
# print(b_n)
# print(m_n)


total = 100000
for m in m_n:
    a = a_n[m[0]-1]
    b = b_n[m[1]-1]
    total = min(total, a+b-m[2])

total = min(total, min(a_n) + min(b_n))
print(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()))
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()))
xyc = [list(map(int, input().split())) for _ in range(M)]

ans = 10 ** 18 + 1
for i in range(A):
    if B - 1 < i:
        tmp = a[i]
    else:
        tmp = a[i] + b[i]
    ans = min(tmp, ans)

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

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

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

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 i in range(M)]

noti=min(a)+min(b)
ans=0
c=0

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

Submission status: Wrong Answer

Solution code:
s = input()
if len(s) % 2 != 0:
    print("No")
    exit()
else:
    S = [s[i] + s[i+1] for i in range(0, len(s), 2)]
    if len(set(S)) == 1 and S[0] == "hi":
        print("Yes")
    else:
        print("No")

Submission status: Wrong Answer

Solution code:
import sys
import bisect
MAX_INT = int(10e15)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

A,B,M = IL()
a = IL()
b = IL()
xyc = [IL() for i in range(M)]

a.sort()
b.sort()

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

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_col(H, n_cols):
    '''
    H is number of rows
    n_cols is number of cols

    A列、B列が与えられるようなとき
    '''
    ret = [[] for _ in range(n_cols)]
    for _ in range(H):
        tmp = list(map(int, read().split()))
        for col in range(n_cols):
            ret[col].append(tmp[col])

    return ret


def read_matrix(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


def read_map(H):
    '''
    H is number of rows
    文字列で与えられた盤面を読み取る用
    '''
    return [read()[:-1] for _ in range(H)]


def read_map_as_int(H):
    '''
    #→1,.→0として読み込む
    '''
    ret = []
    for _ in range(H):
        ret.append([1 if s == '#' else 0 for s in read()[:-1]])
        # 内包表記はpypyでは若干遅いことに注意
        # #numpy使うだろうからこれを残しておくけど
    return ret


# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from fractions import gcd


def lcm(a, b):
    # 最小公約数
    g = gcd(a, b)
    return a * b // g


A, B, M = read_ints()
a = read_ints()
b = read_ints()

ans = 10 ** 9
for _ in range(M):
    x, y, c = read_ints()
    nedan = a[x - 1] + b[y - 1] - c
    ans = min(ans, nedan)

print(ans)

Submission status: Wrong Answer

Solution code:
a,b,m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = float("inf")
for i 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, N = map(int, input().split())
La =list(map(int, input().split())) 
Lb =list(map(int, input().split()))
ans = 10**10
for i in range (N):
  W = list(map(int, input().split())) 
  x = W[0]-1
  y = W[1]-1
  c = W[2]
  price = La[x] + Lb[y] -c
  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()))
ans = a[0]+b[0]
for i in range(m):
    x,y,c = list(map(int, input().split()))
    if a[x-1]+b[y-1]-c<ans: ans = a[x-1]+b[y-1]-c
print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
a, b, M = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

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

ans = min(ans,min(A)+min(B))

print(ans)

Submission status: Wrong Answer

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

a_prices = [int(i) for i in input().split()]
b_prices = [int(i) for i in input().split()]

min_price = min([a + b for a, b in zip(a_prices, b_prices)])

for _ in range(m):
    x, y, c = map(int, input().split())
    x -= 1
    y -= 1
    min_price = min(min_price, a_prices[x] + b_prices[y] - c)
print(min_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()))
ans=min(A)+min(B)
for i in range(m):
    x,y,c=map(int,input().split())
    tmp=A[x-1]+B[y-1]+c
    ans=min(ans,tmp)
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]<mi:
        mi=fri[wari[i][0]-1]+mic[wari[i][1]-1]
print(mi)

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

Submission status: Time Limit Exceeded

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

for s in a:
  for t in b:
    price_list.append(s + t)


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


min_price = price_list[0]

for n in price_list:
  if min_price >= n:
    min_price = n
  elif min_price < n:
    pass


print(min_price)

Submission status: Time Limit Exceeded

Solution code:
# 日立製作所 社会システム事業部 プログラミングコンテスト2020: B – Nice Shopping
A, B, M = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = [int(j) for j in input().split()]
x, y, c = [], [], []
for k in range(M):
    tmp = [int(i) for i in input().split()]
    x.append(tmp[0])
    y.append(tmp[1])
    c.append(tmp[2])

prices = []

for i in range(A):
    for j in range(B):
        prices.append(a[i] + b[j])

for k in range(M):
    prices.append(a[x[k] - 1] + b[y[k] - 1] - c[k])

print(min(prices))

Submission status: Time Limit Exceeded

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

min = a[0] + b[0]
for i in range( len(a)):
    for j in range(len(b)):
        price = a[i] + b[j]
        discountPrice = price
        for k in range(M):
            if i + 1 in m[k] and j + 1 in m[k]:
                discountPrice = price - m[k][2]
            if min > discountPrice:
                min = discountPrice


print(min)

Submission status: Time Limit Exceeded

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

for i in range(m):
  aa.append(a[x[i][0]-1]+b[x[i][1]-1]-x[i][2])
  aa.append(min(a)+min(b))

print(min(aa))

Submission status: Time Limit Exceeded

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

for i in range(m):
  aa.append(a[x[i][0]-1]+b[x[i][1]-1]-x[i][2])
  aa.append(min(a)+min(b))

print(min(aa))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

min_price = float("inf")
for i, price_a in enumerate(a, 1):
    for j, price_b in enumerate(b, 1):
        total_price = price_a + price_b
        if (i, j) in tickets:
            total_price -= tickets[(i, j)]
        if min_price > total_price:
            min_price = total_price

print(min_price)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:

A,B,M =map(int,input().split())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
x = []
for m in range(M):
    x.append([int(i) for i in input().split()])
_min = 10**7
for i in range(len(a)):
	for j in range(len(b)):
		_min = min(a[i]+b[j],_min)

for i in x:
    _min = min( (a[i[0]-1]+b[i[1]-1] - i[2]),_min)
print(_min)

Submission status: Time Limit Exceeded

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)]
ans = []
for m in mlist:
	tmp = alist[m[0]-1] + blist[m[1]-1] -m[2]
	ans.append(tmp)
for a in alist:
	for b in blist:
		ans.append(a + b)
print(min(ans))

Submission status: Time Limit Exceeded

Solution code:
A,B,M = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
oldp = 10**20
c = [[0 for _ in range(B)] for _ in range(A)]
for _ in range(M):
    x, y, cp = map(int,input().split())
    p = a[x-1]+b[y-1]-cp
    if oldp > p:
        oldp = p

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

Submission status: Time Limit Exceeded

Solution code:
A,B,M = map(int,input().split())
A_li = list(map(int,input().split()))
B_li = list(map(int,input().split()))
X = set()
Y = set()
inf = float("inf")
posibility = inf

for m in range(M):
    x,y,c=map(int,input().split())
    tmp_posibility=A_li[x-1]+B_li[y-1]-c
    posibility=min(posibility,tmp_posibility)
    X.add(x)
    Y.add(y)

import itertools 
a_li = set(A_li)-X
b_li = set(B_li)-Y

for a,b in itertools.product(a_li,b_li):
    tmp_posibility = a+b
    posibility = min(posibility,tmp_posibility)



print(posibility)

Submission status: Time Limit Exceeded

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 = []
for i in a:
    for j in b:
        rets += [i + j]
for x, y, c in xyc:
    rets += [a[x-1] + b[y-1] - c]
print(min(rets))

Submission status: Time Limit Exceeded

Solution code:
A,B,m = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
li2=[input() for i in range(m)]
c = []
for i in range(m):
    c.append( [int(x.strip()) for x in li2[i].split()])

ans = 10**6

for i in range(len(a)):
    for j in range(len(b)):
        keep = a[i]+b[j]
        coopon = 0
        for k in range(m):
            if c[k][0]-1 == i and c[k][1]-1 == j and coopon<c[k][2]:

                coopon = c[k][2]

        keep -= coopon

        if keep < ans:
            ans = keep

print(ans)

Submission status: Time Limit Exceeded

Solution code:
A,B,M=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=[list(map(int,input().split())) for i in range(M)]
d = 0
e = 10**10

for i in range(A):
	for j in range(B):
		d = a[i]+b[j]
		if d<e:
			e=d

for i in range(M):
	d=a[c[i][0]-1]+b[c[i][1]-1]-c[i][2]
	if d<e:
		e=d

print(e)

Submission status: Time Limit Exceeded

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)

no_ticket = 10**5
for i in range(A):
    for j in range(B):
        no_ticket2 = a[i] + b[i]
        no_ticket = min(no_ticket, no_ticket2)

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: Time Limit Exceeded

Solution code:
import sys

input = sys.stdin.readline

def main():
    ans = 10**5 * 2
    A, B, M = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    for i in range(A):
        for j in range(B):
            cost = a[i] + b[i]
            ans = min(ans, cost)

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

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
A,B,M=map(int, input().split())
As=list(map(int, input().split()))
Bs=list(map(int, input().split()))
List=[]
for i in range(M):
  List.append(list(map(int, input().split())))
ans=10000000000
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: Time Limit Exceeded

Solution code:
A, B, M = map(int, input().split())
Fre = list(map(int, input().split()))
Mic = list(map(int, input().split()))
Tic = []
Price = 10**5
for i in range(M):
  Tic.append(list(map(int, input().split())))
for i in range(A):
  for j in range(B):
    n = Fre[i] + Mic[j]
    if n < Price:
      Price = n
for i in range(len(Tic)):
  n = Fre[Tic[i][0]-1] + Mic[Tic[i][1]-1] - Tic[i][2]
  if n < Price:
    Price = n
print(Price)

Submission status: Time Limit Exceeded

Solution code:
import itertools 

line1 = input().split()
rei =input().split()
den =input().split()
cupon =[list(map(int,input().split())) for i in range(int(line1[2]))]
rei_den =list(itertools.product(rei , den))
sum_rei_den =[0]*len(rei_den)

for i in range(len(rei_den)):
  sum_rei_den[i] = int(rei_den[i][0])+ int(rei_den[i][1])

mi = min(sum_rei_den)

for s in range(int(line1[2])):
  total =int(rei[cupon[s][0]-1]) +int(den[cupon[s][1]-1]) - cupon[s][2]
  if mi > total:
    mi =total
print(mi)

Submission status: Time Limit Exceeded

Solution code:
A, B, M = (int(x) for x in input().split())
al = [int(x) for x in input().split()]
bl = [int(x) for x in input().split()]
ml = [[int(x) for x in input().split()] for _ in range(M)]
"""
price = []
for l in ml:
    price.append(al[l[0]-1] + bl[l[1]-1] - l[2])
for x in al:
    for y in bl:
        price.append(x+y)
"""
price = [al[l[0]-1] + bl[l[1]-1] - l[2] for l in ml] + [x + y for x in al for y in bl] 
print(min(price))

Submission status: Time Limit Exceeded

Solution code:
#入力処理
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
waribiki=[[0]*B]*A
for i in range(M):
    x_input, y_input, c_input = map(int, input().split())
    if waribiki[x_input-1][y_input-1]<c_input:
        waribiki[x_input-1][y_input-1]=c_input

#処理
inexpensive=200000
for i in range(A):
    for j in range(B):
        if (int(a[i])+int(b[j]))-waribiki[i][j] < inexpensive:
            inexpensive = (int(a[i])+int(b[j]))-waribiki[i][j]

print(inexpensive)

Submission status: Time Limit Exceeded

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):
    x_input, y_input, c_input = map(int, input().split())
    x.append(x_input)
    y.append(y_input)
    c.append(c_input)

#処理
kingaku = []
tem=[]
tem1=[]
for i in range(A):
    for j in range(B):
        tem.append(int(a[i])+int(b[j]))
    kingaku.append(tem)
    tem = []

waribiki=[[0]*B]*A
for i in range(M):
    if waribiki[x[i]-1][y[i]-1] < c[i]:
        waribiki[x[i]-1][y[i]-1] = c[i]

inexpensive = 200000
for i in range(A):
    for j in range(B):
        if kingaku[i][j]-waribiki[i][j] < inexpensive:
            inexpensive=kingaku[i][j]-waribiki[i][j]

print(inexpensive)

Submission status: Time Limit Exceeded

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

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

total_min = min(a_list) + min(b_list)
for x,y,c in xyc_list:
    if a_list[x-1] in a_list and b_list[y-1] in b_list:
        total = a_list[x-1] + b_list[y-1] - c
        if total_min > total:
            total_min = total

print(total_min)

Submission status: Time Limit Exceeded

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

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

total_list = []
for x,y,c in xyc_list:
    if a_list[x-1] in a_list and b_list[y-1] in b_list:
        total = a_list[x-1] + b_list[y-1] - c
        total_list.append(total)

nonChicket = min(a_list) + min(b_list)

if min(total_list) < nonChicket:
    print(min(total_list))
else:
    print(nonChicket)

Submission status: Time Limit Exceeded

Solution code:
a,b,m = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = [tuple(map(int,input().split())) for i in range(m)]
p = []
x = 0
p.append(min(a)+min(b))
for ka,ai in enumerate(a):
    for kb,bi in enumerate(b):
        for t in c:
            if t[0]==ka+1 and t[1]==kb+1:
                x = t[2]
                p.append(ai+bi-x)
print(min(p))

Submission status: Time Limit Exceeded

Solution code:
a,b,m = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = [tuple(map(int,input().split())) for i in range(m)]
p = []
x = 0
for ka,ai in enumerate(a):
    for kb,bi in enumerate(b):
        for t in c:
            if t[0]==ka+1 and t[1]==kb+1:
                x = t[2]
            p.append(ai+bi-x)
print(min(p))

Submission status: Time Limit Exceeded

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())
min=a[0]+b[0]
min1=0
for i in range(A):
    for j in range(B):
        for t in range(M):
            if i+1==x[t] and j+1==y[t]:
                min1=a[i]+b[j]-c[t]
            else:
                min1=a[i]+b[j]
            if min >= min1:
                min = min1
print(min)

Submission status: Time Limit Exceeded

Solution code:
A,B,M=map(int,input().split())
x=[0]*M
y=[0]*M
c=[0]*M
a=list(map(int,input().split()))
b=list(map(int,input().split()))
for i in range(M):
    x[i],y[i],c[i]=map(int,input().split())
min=a[0]+b[0]
min1=0
for i in range(A):
    for j in range(B):
        for t in range(M):
            if i+1==x[t] and j+1==y[t]:
                min1=a[i]+b[j]-c[t]

            else:
                min1=a[i]+b[j]
            if min >= min1:
                min = min1
print(min)

Submission status: Time Limit Exceeded

Solution code:
A,B,M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
m=[]
for i in range(M):
    array = list(map(int, input().strip().split()))
    m.append(array)

def hitachi02(a,b,m):
    results=[]
    for i in range(len(a)):
        for j in range(len(b)):
            for k in range(len(m)):
                if i+1 == m[k][0] and j+1 == m[k][1]:
                    cal = a[i]+b[j]-m[k][2]
                else:
                    cal = a[i]+b[j]
                results.append(cal)
    result=min(results)
    return result

result=hitachi02(a,b,m)
print(result)

Submission status: Time Limit Exceeded

Solution code:
S = [int(e) for e in input().split()]
list_a =  [int(e) for e in input().split()]
list_b =  [int(e) for e in input().split()]

dis_list = []

for i in range(S[2]):
    dis_list.append([int(e) for e in input().split()])

cost_list = []
min_num = min(list_a) + min(list_b)

for i in list_a:
    for j in list_b:
        cost_list.append(i+j)


for l in dis_list:
    if (cost_list[S[0]*(l[0]-1)+l[1]-1] - l[2]) < min_num:
        min_num = cost_list[S[0]*(l[0]-1)+l[1]-1] - l[2]

print(min_num)

Submission status: Time Limit Exceeded

Solution code:
S = [int(e) for e in input().split()]
list_a =  [int(e) for e in input().split()]
list_b =  [int(e) for e in input().split()]

dis_list = []

for i in range(S[2]):
    dis_list.append([int(e) for e in input().split()])

cost_list = []

for i in list_a:
    for j in list_b:
        cost_list.append(i+j)


for l in dis_list:
    cost_list.append(cost_list[S[0]*(l[0]-1)+l[1]-1] - l[2])

min_num = cost_list[0]

for i in cost_list:
    if i < min_num:
        min_num = i

print(min_num)

Submission status: Time Limit Exceeded

Solution code:
S = [int(e) for e in input().split()]
# S = list(map(int, input().replace(' ', '')))
list_a =  [int(e) for e in input().split()]
# list_a = list(map(int, input().replace(' ', '')))
list_b =  [int(e) for e in input().split()]
# list_b = list(map(int, input().replace(' ', '')))

dis_list = []

for i in range(S[2]):
    dis_list.append([int(e) for e in input().split()])

cost_list = []

for i in list_a:
    for j in list_b:
        cost_list.append(i+j)

for l in dis_list:
    cost_list.append(cost_list[S[0]*(l[0]-1)+l[1]-1] - l[2])

print(min(cost_list))
# print('cost_list:',cost_list)
# print('list_a:',list_a)
# print('list_b:',list_b)

Submission status: Time Limit Exceeded

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 = []
mini = 200000
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: Time Limit Exceeded

Solution code:
a=input()
a1=input()
a2=input()
a=a.split()
a1=a1.split(" ")
a2=a2.split()
l=[]
for i in a1:
    for j in a2:
     l.append(int(i)+int(j))
for i in range(int(a[2])):
    dis=input()
    dis=dis.split()
    # l.append(int(a1[int(dis[0])-1])+int(a2[int(dis[1])-1])-int(dis[2]))
    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: Time Limit Exceeded

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

minc=min(a)+min(b)

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

  if cash<minc:
    minc=cash


print(minc)

Submission status: Time Limit Exceeded

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

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

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


amount = 9999999999999999999999999
for i in range(A):
    for j in range(B):
        tmp_amount = A_price_list[i] + B_price_list[j] - discount_list[i][j]
        amount = min(amount, tmp_amount)

print(amount)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin

A, B, M = [int(x) for x in stdin.readline().rstrip().split()]
a = [int(x) for x in stdin.readline().rstrip().split()]
b = [int(x) for x in stdin.readline().rstrip().split()]
X = [[int(x) for x in stdin.readline().rstrip().split()] for _ in range(M)]

L = []
for a_i in a:
    for b_i in b:
        L.append(a_i + b_i)

for x in X:
    L.append(a[x[0]-1] + b[x[1]-1] - x[2])
    
print(min(L))