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: Accepted

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

cost=[]
for _ in range(M):
    x, y, c = list(map(int, input().rstrip().split()))
    tot = a[x-1] + b[y-1] - c
    cost.append(tot)
    
cost.append(min(a)+min(b))
print(min(cost))

Submission status: Accepted

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

Submission status: Accepted

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

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

sum = min(a) + min(b)

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)
    sum = min(sum, num)

print(sum)

Submission status: Accepted

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

al=[]
a=input().split()
for i in a:
    al.append(int(i))
bl = []
b=input().split()
for i in b:
    bl.append(int(i))

cl=[]
for i in range(M):
    l=[]
    c = input().split()
    for i in c:
        l.append(int(i))
    cl.append(l)
    
l=[]
for i in cl:
    a=0
    a=al[i[0]-1]+bl[i[1]-1]-i[2]
    l.append(a)

Min=min(al) + min(bl)
if min(l) < Min:
    print(min(l))
else:
    print(Min)

Submission status: Accepted

Solution code:
def main():
  import sys
  
  a, b, m = map(int, input().split())
  a = list(map(int, sys.stdin.readline().split()))
  b = list(map(int, sys.stdin.readline().split()))
  ans = min(a) + min(b)
  
  for _ in range(m):
    i, j, c = map(int, input().split())
    ans = min(ans, a[i-1]+b[j-1]-c)
  
  print(ans)
  
if __name__=='__main__':
  main()

Submission status: Accepted

Solution code:
a, b, m = map(int,raw_input().split())
al = map(int,raw_input().split())
bl = map(int,raw_input().split())
low = min(al)+min(bl)
x = [0] * m
y = [0] * m
c = [0] * m

for i in range(m):
    x[i],y[i],c[i] = map(int, raw_input().split())
    x[i] -= 1
    y[i] -= 1
 
for i in range(m):
    low = min(low,al[x[i]]+bl[y[i]]-c[i])

print low

Submission status: Accepted

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(tmp,ans)
print(ans)

Submission status: Accepted

Solution code:
r,p,m=range,print,min
n,a,b=[list(map(int,input().split()))for i in r(3)]
l=[]
for i in r(n[2]):
  x,y,z=map(int,input().split())
  l.append(a[x-1]+b[y-1]-z)
p(m([m(a)+m(b),m(l)]))

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from sys import stdin


def calc_min_price(a_list, b_list,  pricedown_list):
    # 割引しない場合の最安組み合わせを算出する
    min_a = min(a_list)
    min_b = min(b_list)
    min_price = min_a + min_b

    # 割引したものも含めて一番安い値段を算出する
    for i, j, price in pricedown_list:
        min_price = min(min_price, a_list[i-1]+b_list[j-1]-price)

    return min_price


# 入力
a, b, m = map(int, input().split())

# 商品値段リスト
a_list = [int(x) for x in stdin.readline().rstrip().split()]
b_list = [int(x) for x in stdin.readline().rstrip().split()]

# 値引きリスト
pricedown_list = []
for i in range(m):
    pricedown_list.append([int(x) for x in stdin.readline().rstrip().split()])

# 最小金額を計算する
min_price = calc_min_price(a_list, b_list,  pricedown_list)

# 出力
print(min_price)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from sys import stdin

def calc_ab_price_without_pricedown(a_list, b_list):
    ab_price = [[a_list[j]+b_list[i] for i in range(len(b_list))] for j in range(len(a_list))]

    return ab_price


def calc_pricedown(ab_price, pricedown_list):
    """値段表から値引きする"""
    for i, j, price in pricedown_list:
        for k, l, price2 in pricedown_list:
            if (i, j) == (k, l) and price >= price2:
                continue
            elif (i, j) == (k, l) and price < price2:
                price = 0

        ab_price[i-1][j-1] -= price

    return ab_price

def generate_table(a_list, b_list,  pricedown_list):
    min_a = min(a_list)
    min_b = min(b_list)
    min_price = min_a + min_b

    for i, j, price in pricedown_list:
        min_price = min(min_price, a_list[i-1]+b_list[j-1]-price)

    return min_price


def calc_min_price(a_list, b_list, ab_price):
    min_price = float('inf')
    for i in range(len(a_list)):
        for j in range(len(b_list)):
            min_price = min(ab_price[i][j], min_price)
    return min_price

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

a_list = [int(x) for x in stdin.readline().rstrip().split()]
b_list = [int(x) for x in stdin.readline().rstrip().split()]

pricedown_list = []
for i in range(m):
    pricedown_list.append([int(x) for x in stdin.readline().rstrip().split()])
    # pricedown_list.append((list(map(int, input().split()))))


# 割引せずに購入する場合の合計金額のうち、最低金額を算出
# ab_price = calc_ab_price_without_pricedown(a_list, b_list)

# 最低金額を算出
# min_price = calc_min_price(a_list, b_list, ab_price)

# 割引の値段を含めて考える
# pricedowned_ab = calc_pricedown( ab_price, pricedown_list)

min_price = generate_table(a_list, b_list,  pricedown_list)

# 値引き後の最低金額を算出
# min_price = calc_min_price(a_list, b_list, price_table)

print(min_price)

Submission status: Accepted

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

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

ans = min(a) + min(b)

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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 _ in range(M)]
ans = min(A) + min(B)
for cp in C:
    temp = A[cp[0]-1] + B[cp[1]-1] - cp[2]
    ans = min(ans,temp)

print(ans)

Submission status: Accepted

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

ma=int(1000000)
mb=int(1000000)
for i in range(a):
    if A[i]<ma:
        ma=A[i]
for i in range(b):
    if B[i]<mb:
        mb=B[i]

ans=ma+mb

for i in range(m):
    x,y,c=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: Accepted

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

reizouko = list(map(int,input().split()))
renji = list(map(int,input().split()))

kupon_min = 10**11

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

normal_min = min(reizouko) + min(renji)

print(min(normal_min,kupon_min))

Submission status: Accepted

Solution code:
import sys
import numpy as np

read = sys.stdin.read
readline = sys.stdin.readline

A, B, M = map(int, readline().split())
a = np.array(readline().split(), np.int64)
b = np.array(readline().split(), np.int64)
xyc = np.array(read().split(), np.int64)
x = xyc[::3]
y = xyc[1::3]
c = xyc[2::3]
answer = np.min(a) + np.min(b)
answer = min(answer, np.min(a[x - 1] + b[y - 1] - c))
print(answer)

Submission status: Accepted

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

a_A = list(map(int, input().split()))
b_B = list(map(int, input().split()))

summ = min(a_A) + min(b_B)

x = []
y = []
c = []

for i in range(m):
    x, y, c = map(int, input().split())
    # x.append(x_t)
    # y.append(y_t)
    # c.append(c_t)
    discount = a_A[x - 1] + b_B[y - 1] - int(c)

    if discount < summ:
        summ = discount

print(summ)

Submission status: Accepted

Solution code:
A,B,M=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
w=[[0,0,0] for i in range(0,M)]
for i in range(0,M):
    w[i][0],w[i][1],w[i][2]=map(int,input().split())

ans=min(a)+min(b)
for i in range(0,M):
    test=a[w[i][0]-1]+b[w[i][1]-1]-w[i][2]
    if test<ans:
        ans=test

print(ans)

Submission status: Accepted

Solution code:
from sys import stdin

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

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

print(minimum)

Submission status: Accepted

Solution code:


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

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

print(ans)

Submission status: Accepted

Solution code:
a,b,m = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
mina = min(a)
minb = min(b)
ans = mina + minb
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: Accepted

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

Submission status: Accepted

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

if M == 0:
  exit()

result = min(a) + min(b)
for _ in range(M):
    x, y, c = map(int, input().split())
    t = a[x - 1] + b[y - 1] - c
    if t < result:
        result = t
print(result)

Submission status: Accepted

Solution code:
A, B, M = list(map(int,input().split()))
list_a = list(map(int,input().split()))
list_b = list(map(int,input().split()))
buy = []
buy.append(min(list_a) + min(list_b))
for i in range(M):
    x, y, c = list(map(int,input().split()))
    buy.append(list_a[x-1] + list_b[y-1] - c)
answer = min(buy)
print(answer)

Submission status: Accepted

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

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

print(min)

Submission status: Accepted

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

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

sum_origin=min(a)+min(b)

sum_=[]

for x_,y_,c_ in x:
  
  sum_disc=a[x_-1]+b[y_-1]-c_
  sum_.append(sum_disc)

if min(sum_)>sum_origin:
  print(sum_origin)

elif min(sum_)<sum_origin: 
  print(min(sum_))

elif min(sum_) == sum_origin:
  print(min(sum_))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from collections import *
from itertools import *
from bisect import *
from heapq import *
import copy
import math
from fractions import gcd

_,__,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)]

value=min(A)+min(B)


for x,y,c in XYC:
    value=min(value,A[x-1]+B[y-1]-c)
print(value)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

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

print(min(ans))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    A,B,M = [int(n) for n in input().split()]
    arrA = [int(n) for n in input().split()]
    arrB = [int(n) for n in input().split()]
    arrC = []
    for i in range(M): 
        x,y,c = [int(n) for n in input().split()]
        x-=1
        y-=1
        arrC.append((x,y,c))
    res = min(arrA) + min(arrB)
    for i in range(M):
        wari = arrC[i]
        price = arrA[wari[0]] + arrB[wari[1]] - wari[2]
        res = min(res, price)
    print(res)
main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
A,B,M=map(int, input().split())
a=list(map(int, input().split()))
b=list(map(int, input().split()))
c=[]
wari=[]
warik=0
ans=0
for i in range(M):
    c+=list(map(int, input().split()))
for i in range(M):
    wari.append(a[c[i*3]-1]+b[c[2*i+(i+1)]-1]-c[2+3*i])    
warik=min(wari)
ans=min(a)+min(b)
if ans<warik:
    print(ans)
else:
    print(warik)

Submission status: Accepted

Solution code:
n_a,n_b,M=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
price=[]
for i in range(M):
    X=list(map(int,input().split()))
    price.append(A[X[0]-1]+B[X[1]-1]-X[2])
price.append(min(A)+min(B))
print(min(price))

Submission status: Accepted

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

Submission status: Accepted

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

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

print(min_cost)

Submission status: Accepted

Solution code:
a,b,m = list(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 = list(map(int,input().split()))
    ans = min(A[x-1]+B[y-1]-c,ans)

print(ans)

Submission status: Accepted

Solution code:
import sys
def ipt():
    return map(int, sys.stdin.readline().strip().split())

_A, _B, m = ipt()
a = list(ipt())
b = list(ipt())
data = [list(ipt()) for _ in range(m)]
 
ans = min(a) + min(b)
for x, y, c in data:
  case = a[x-1] + b[y-1] - c
  ans = min(ans, case)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

def resolve():
    input = sys.stdin.readline
    A, B, M = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    grid=[list(map(int,input().split())) for i in range(M)]

    res = min(a) + min(b)

    for x, y, c in grid:
        res = min(res, a[x-1]+b[y-1]-c)

    print(res)
    
resolve()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

import sys
from collections import Counter

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N, M, L = MAP()
A = LIST()
B = LIST()

mn = min(A) + min(B)
for _ in range(L):
    x, y, c = MAP()
    x -= 1; y -= 1
    mn = min(mn, A[x] + B[y] - c)
print(mn)

Submission status: Accepted

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

ans = min(a_list) + min(b_list)
for discount in sys.stdin:
    x, y, c = map(int, discount.split())
    ans = min(ans, a_list[x - 1] + b_list[y - 1] - c)
print(ans)

Submission status: Accepted

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

an = list(map(int, input().split(' ')))
bn = list(map(int, input().split(' ')))

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

# print(A, B, M)
# print(an)
# print(bn)
# print(mn)


total = min(an) + min(bn)

for a,b,c in mn:
    total = min(total, an[a-1]+bn[b-1]-c)
print(total)

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline
from itertools import accumulate
sys.setrecursionlimit(100000000)

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

  

if __name__=='__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# AtCoder Hitachi B
A, B, M = map(int, input().split())
Ma = [int(_) for _ in input().split()]
Mb = [int(_) for _ in input().split()]
Mm = [[int(_) for _ in input().split()] for __ in range(M)]
# unuse vaucher
r0 = min(Ma) + min(Mb)
# use vaucher
r1 = min([Ma[x-1]+Mb[y-1]-c for x,y,c in Mm])
print(min(r0,r1))

Submission status: Accepted

Solution code:
import sys
 
A, B, M = map(int, sys.stdin.readline().split())
*a, = map(int, sys.stdin.readline().split())
*b, = map(int, sys.stdin.readline().split())
xyc = zip(*[map(int, sys.stdin.read().split())] * 3)
 
def main():
    res = min(a) + min(b)
 
    for x, y, c in xyc:
        res = min(res, a[x-1] + b[y-1] - c)
    return res
    
if __name__ == '__main__':
    ans = main()
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def resolve():
    A, B, M = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    grid=[list(map(int,input().split())) for i in range(M)]

    res = min(a) + min(b)

    for x, y, c in grid:
        res = min(res, a[x-1]+b[y-1]-c)

    print(res)
    
resolve()

Submission status: Accepted

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

mn = [min(a) + min(b)]

for value in xyc:
    mn.append(a[value[0] - 1] + b[value[1] - 1] - value[2])

print(min(mn))

Submission status: Accepted

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

Submission status: Accepted

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

disc = [list(map(int, input().split())) for i in range(m)]
import numpy as np


from collections import deque
ans = []

ans = deque(ans)

for i in range(m):
    ans.append( a1[disc[i][0]-1] + b1[disc[i][1]-1] - disc[i][2] )

ans = list(ans)

print(min( min(ans), min(a1)+min(b1) ))

Submission status: Accepted

Solution code:
f=lambda:list(map(int,input().split()))
_,_,n=f();a,b=f(),f();m=min(a)+min(b)
for _ in range(n):x,y,c=f();m=min(m,a[x-1]+b[y-1]-c)
print(m)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
A, B, M = list(map(int,input().split()))
a = np.array(list(map(int,input().split())))
b = np.array(list(map(int,input().split())))

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

x = np.array(x)
min_val = a.min() + b.min()

for i in range(len(x)) :
    if min_val > a[x[i][0]-1] + b[x[i][1]-1] - x[i][2] :
        min_val = a[x[i][0]-1] + b[x[i][1]-1] - x[i][2]

print(min_val)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

x, y, m = [int(i) for i in input().split()]

a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
num = [min(a)+min(b)]

for _ in range(m):
    tmp = [int(i) for i in input().split()]
    num.append(a[tmp[0]-1]+b[tmp[1]-1]-tmp[2])

print(min(num))

Submission status: Accepted

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

reizou = input()
reizou_list = reizou.split()

renji = input()
renji_list = renji.split()
cupon_list = []

price = int(min(reizou_list)) + int(min(renji_list))

for i in range(int(M)):
    # coupon = input()
    # coupon_sub_list = coupon.split()
    # cupon_list.append(coupon_sub_list)
    
    a,b,c = map(int,input().split())
    price_coupon = int(reizou_list[int(a) - 1]) + int(renji_list[int(b) - 1]) - int(c)
    if price > price_coupon: price = price_coupon

print(price)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
"""
B
"""
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=float("inf")
for x,y,c in xyc:
    ans=min(ans,a[x-1]+b[y-1]-c)
ans=min(ans,min(a)+min(b))
print(ans)

Submission status: Accepted

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

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

    res = min(a) + min(b)
    for m in grid:
        if m[0]-1 < A and m[1]-1 < B:
            tmp = a[m[0]-1] + b[m[1]-1] - m[2]
        
            if tmp < res:
                res = tmp

    print(res)
    
resolve()

Submission status: Accepted

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 = min(A) + min(B)
for x, y, c in XYC:
  x -= 1
  y -= 1
  cand = A[x] + B[y] - c
  ans = min(ans, cand)
print(ans)

Submission status: Accepted

Solution code:
A, B, M = [int(x) for x in input().split()]
Aprices = [int(x) for x in input().split()]
Bprices = [int(x) for x in input().split()]
mins = min(Aprices) + min(Bprices)
for i in range(M):
    a, b, c = [int(x) for x in input().split()]
    current = Aprices[a -1] + Bprices[b - 1] - c
    mins = min(mins, current)

print(mins)

Submission status: Accepted

Solution code:
import math
import fractions

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

def ValueToBits(x,digit):
    res = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        res[i]=now%2
        now = now >> 1
    return res

def BitsToValue(arr):
    n = len(arr)
    ans = 0
    for i in range(n):
        ans+= arr[i] * 2**i
    return ans

def ValueToArray10(x, digit):
    ans = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        ans[digit-i-1] = now%10
        now = now //10
    return ans

def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p
'''
p = 10 ** 9 + 7
N = 10 ** 6 + 2
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用

for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)
'''


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

aa,bb,m = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ms = []
for i in range(m):
    ms.append(list(map(int, input().split())))


ans = 10**19
for i in range(m):
    now = a[ms[i][0]-1] + b[ms[i][1]-1] - ms[i][2]
    if(ans > now):
        ans = now
   
mina = min(a)
minb = min(b)
if(mina+minb < ans):
    ans = mina+minb
print(ans)

Submission status: Accepted

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
cost = 10 ** 30
for _ in xrange(M):
    x, y, c = map(int, raw_input().split())
    cost = min(cost, a_s[x-1] + b_s[y-1] - c)
    w[x-1][y-1] = max(w[x-1][y-1], c)

a_s = sorted(enumerate(a_s), key=lambda t: t[1])
b_s = sorted(enumerate(b_s), key=lambda t: t[1])
for i, a in a_s:
    if a + b_s[0][1] >= cost:
        break
    for j, b in b_s:
        if w[i][j] > 0:
            break
        cost = min(cost, a + b)

print cost

Submission status: Accepted

Solution code:
a, b, m = map(int, input().split(' '))
A = list(map(int, input().split(' ')))
B = list(map(int, input().split(' ')))
m1 = min(A) + min(B)
m2 = 1000000
for i in range(m):
    l = list(map(int, input().split(' ')))
    lp = A[l[0] - 1] + B[l[1] - 1] - l[2]
    if lp < m2:
        m2 = lp        
print(m1 if m1 < m2 else m2)

Submission status: Accepted

Solution code:
import sys
A,B,M = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
ans = min(a) + min(b)
w = [list(map(int,input().split())) for i in range(M)]
for i in range(M):
    if a[w[i][0]-1] + b[w[i][1]-1] - w[i][2] < ans:
        ans = a[w[i][0]-1] + b[w[i][1]-1] - w[i][2]
print(ans)

Submission status: Accepted

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

a=list(map(int, input().split()))
b=list(map(int, input().split()))
dis=[list(map(int,input().split()))  for l in range(M)]

comp1=a[dis[0][0]-1]+b[dis[0][1]-1]-dis[0][2]
for l in range(M):
    y=a[dis[l][0]-1]+b[(dis[l][1])-1]-dis[l][2]
    if comp1>y:
        comp1=y

comp2=min(a)+min(b)
                  
print(min(comp1,comp2))