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:
ALEN, BLEN, M = map(int, input().split())
A = [int(n) for n in input().split()]
B = [int(n) for n in input().split()]

price = float('inf')

for i in range(M):
	ai, bi, c = map(int, input().split())
	waribiki = A[ai-1] + B[bi-1] - c
	if waribiki < price:
		price = waribiki

nowaribiki = min(A) + min(B)

if nowaribiki < price:
	price = nowaribiki

print(price)

Submission status: Accepted

Solution code:
def resolve():
    A, B, M = map(int, input().split())  
    a_list = list(map(int, input().split()))
    b_list = list(map(int, input().split()))
    x_list = []

    for i in range(M):
        x_list.append(list(map(int, input().split())))

    min_prace = min(a_list) + min(b_list)

    for i_list in x_list:
        tmp_prace = a_list[i_list[0]-1] + b_list[i_list[1]-1] - i_list[2]
        if tmp_prace < min_prace:
            min_prace = tmp_prace

    print(min_prace)

if __name__ == "__main__":
    resolve()

Submission status: Accepted

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


def solve(A: int, B: int, M: int, a: "List[int]", b: "List[int]", x: "List[int]", y: "List[int]", c: "List[int]"):

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

    print(min_)
    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: Accepted

Solution code:
import sys

numbers=input().rstrip().split(" ")
A=int(numbers[0])
B=int(numbers[1])
M=int(numbers[2])

ref=input().rstrip().split(" ")
mic=input().rstrip().split(" ")

koopons=[]
for line in sys.stdin.readlines():
    koopons.append(line.rstrip().split(" "))

'''print(A)
print(B)
print(M)
print(ref)
print(mic)
print(koopons)'''

prices=[]
for koopon in koopons:
    price=int(ref[int(koopon[0])-1])+int(mic[int(koopon[1])-1])-int(koopon[2])
    prices.append(price)
#print(prices)
lowest2=sorted(prices)[0]
refs=sorted(ref)
mics=sorted(mic)
lowest1=int(refs[0])+int(mics[0])
#print(lowest1)
#print(lowest2)
if lowest1>=lowest2:
    print(lowest2)
else:
    print(lowest1)

Submission status: Accepted

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

min_a = min(Alist)
min_b = min(Blist)
answer = min_a + min_b

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

if answer > 0:
    print(answer)
else:
    print(0)

Submission status: Accepted

Solution code:
import itertools

a, b, m = map(int, input().split())
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
m_list = [list(map(int, input().split())) for _ in range(m)]

kumiawase_kingaku = min(a_list) + min(b_list)

for x, y, c in m_list:
    reizouko = a_list[x-1]
    denshirenji = b_list[y-1]
    kingaku = reizouko + denshirenji - c
    if kingaku < kumiawase_kingaku:
        kumiawase_kingaku = kingaku

print(kumiawase_kingaku)

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

min_a = min(a)
min_b = min(b)

min_cost = min_a + min_b

for i in range(M):
    kari = a[xyc[i][0]-1] + b[xyc[i][1]-1] -xyc[i][2]
    if kari < min_cost:
        min_cost = kari
        
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):
    tmpx, tmpy, tmpc = list(map(int, input().split()))
    val = a[tmpx-1]+b[tmpy-1]-tmpc
    if ans > val:
        ans = val

print(ans)

Submission status: Accepted

Solution code:
import sys
l = sys.stdin.read().split('\n')[:-1]
p = [list(map(int, i.split())) for i in l[1:3]]
ans = (p[0][d[0] - 1] + p[1][d[1] - 1] - d[2] for d in (list(map(int, i.split())) for i in l[3:]))
print(min(min(ans), min(p[0]) + min(p[1])))

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 = []

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

xyc.sort()

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

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

ans = 100000000

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

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

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

Submission status: Accepted

Solution code:
def main():
    A,B,M = map(int,input().split())
    Al = list(map(int,input().split()))
    Bl = list(map(int,input().split()))
    xyc = [list(map(int,input().split())) for i in range(M)]
    minAB = min(Al) + min(Bl)
    now_min = minAB
    for m in xyc:
        s = Al[m[0]-1] + Bl[m[1]-1] - m[2]
        if s < now_min:
            now_min = s

    print(now_min)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def main(): 
    _, _, m = map(int,input().split())
    reizo = list(map(int,input().split()))
    renzi = list(map(int,input().split()))
    waribiki = [list(map(int,input().split())) for i in range(m)]

    min_cost = min(reizo) + min(renzi)

    for i in range(m):
        cost = reizo[waribiki[i][0]-1] + renzi[waribiki[i][1]-1] - waribiki[i][2]

        if cost < min_cost:
            min_cost = cost
    
    print(min_cost)


main()

Submission status: Accepted

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

def calc_money(x, y, c):
  return A_list[x-1] + B_list[y-1] - c

money = 10**7
for i in range(M):
  x, y, c = map(int, input().split())
  tmp_money = calc_money(x, y, c)
  if tmp_money < money:
    money=tmp_money
print(min(money,min(A_list)+ min(B_list)))

Submission status: Accepted

Solution code:
ans = []

number = input().split(" ")
A = int(number[0])
B = int(number[1])
M = int(number[2])
a = input().split(" ")
a = list(map(int, a))
b = input().split(" ")
b = list(map(int, b))

for i in range(M):
    dis = input().split(" ")
    x = int(a[int(dis[0])-1]) + int(b[int(dis[1])-1]) - int(dis[2])
    ans.append(x)
a.sort()
b.sort()
ans.append(int(a[0])+int(b[0]))
ans = list(map(int, ans))
ans.sort()
print(ans[0])

Submission status: Accepted

Solution code:
from sys import stdin


def main():
    input = lambda: stdin.readline()[:-1]
    A, B, M = map(int, input().split())
    AA = tuple(map(int, input().split()))
    BB = tuple(map(int, input().split()))
    XYC = [tuple(map(int, input().split())) for _ in [0] * M]

    case0 = min(AA) + min(BB)
    case1 = case0
    for x, y, c in XYC:
        case1 = min(case1, AA[x-1] + BB[y-1] - c)
    print(case1)


main()

Submission status: Accepted

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

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

for _ in range(m):
    i, j, k = list(map(int, input().split()))
    p.append(a[i-1] + b[j-1] - k)
ppt = min(p)

if ans > ppt: ans = ppt

print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8

line1 = [int(x) for x in input().rstrip().split(" ")]
num_refrigeratores, num_microwaves, num_discount_tickets = line1[0], line1[1], line1[2]

ls_price_refrigeratores = [int(x) for x in input().rstrip().split(" ")]
ls_price_microwaves = [int(x) for x in input().rstrip().split(" ")]

price_min = min(ls_price_refrigeratores) + min(ls_price_microwaves)

for _ in range(num_discount_tickets):
    linen = [int(x) for x in input().rstrip().split(" ")]
    total_price = ls_price_refrigeratores[linen[0] - 1] + ls_price_microwaves[linen[1] - 1] - linen[2]
    if price_min > total_price:
        price_min = total_price

print(price_min)

Submission status: Accepted

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


def solve(A: int, B: int, M: int, a: "List[int]", b: "List[int]", x: "List[int]", y: "List[int]", c: "List[int]"):
    min_no_coupon = sorted(a)[0] + sorted(b)[0]

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

    print(min(min_coupon, min_no_coupon))

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

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

print(ans)

Submission status: Accepted

Solution code:
class SetItem:
    def __init__(self, a, b, sub):
        self.a = a
        self.b = b
        self.sub = sub

    def get_total(self, a_list, b_list):
        a_value = a_list[self.a-1]
        b_value = b_list[self.b-1]
        return a_value + b_value - self.sub


a, b, m = map(int, input().split())
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
set_list = []
for _ in range(m):
    a, b, sub = map(int, input().split())
    set_item = SetItem(a, b, sub)
    set_list.append(set_item.get_total(a_list, b_list))

set_list.sort()
a_list.sort()
b_list.sort()
ans = a_list[0]+b_list[0] if a_list[0]+b_list[0] < set_list[0] else set_list[0]
print(ans)

Submission status: Accepted

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

a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))

discount_list = [tuple(map(int, input().split())) for _ in range(M)]

ans = sorted(a_list)[0] + sorted(b_list)[0]

for discount in discount_list:
    tmp = a_list[discount[0]-1] + b_list[discount[1]-1] - discount[2]
    if ans > tmp:
        ans = tmp

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

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

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

Submission status: Accepted

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

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

for i in range(0, M):
    x, y, c = map(int,input().split())
    min_can = a[x-1] + b[y-1] -c
    if total_min > min_can:
        total_min = min_can
print(total_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()))
xyc = [list(map(int,input().split())) for __ in range(m)]

no_use = min(A)+min(B)
use=A[xyc[0][0]-1]+B[xyc[0][1]-1]-xyc[0][2]
for i in range(1,m):
    use = min(use,A[xyc[i][0]-1]+B[xyc[i][1]-1]-xyc[i][2])
print(min(no_use,use))

Submission status: Accepted

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

normal_min = min(a_list) + min(b_list)
for m_list_it in m_list:
    x, y, c = m_list_it[0], m_list_it[1], m_list_it[2]
    spe_min = a_list[x-1] + b_list[y-1] - c
    if spe_min < normal_min:
        normal_min = spe_min
print(normal_min)

Submission status: Accepted

Solution code:
A, B, M = input().split(" ")
M = int(M)
A_list = input().split(" ")
A_list = list(map(int, A_list))
B_list = input().split(" ")
B_list = list(map(int, B_list))
M_min = 99999999
for i in range(M):
    m = input().split(" ")
    m = list(map(int, m))
    if M_min > A_list[m[0]-1]+B_list[m[1]-1]-m[2]:
        M_min = A_list[m[0]-1]+B_list[m[1]-1]-m[2]
AB_min = min(A_list)+min(B_list)
if AB_min < M_min:
    print(AB_min)
else:
    print(M_min)

Submission status: Accepted

Solution code:
import math
import itertools
import statistics
# = int(input())
A, B, 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):
    X, Y, Z = [int(j) for j in input().split()]
    x.append(X)
    y.append(Y)
    c.append(Z)

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

print(m)

Submission status: Accepted

Solution code:
a, b, m =  map(int, input().split())
aa = list(map(int, input().split()))
bb = list(map(int, input().split()))
x = [list(map(int, input().split())) for _ in range(m)]
ln = []
for i in range(m):
    ln.append(aa[x[i][0] - 1] + bb[x[i][1] - 1] - x[i][2])
ln.append(min(aa) + min(bb))
print(min(ln))

Submission status: Accepted

Solution code:
a,b,m=(int(x) for x in input().split())
la = list(map(int,input().split()))
lb = list(map(int,input().split()))
mi = (min(la) + min(lb))
for i in range(m):
	x,y,c=(int(x) for x in input().split())
	z = la[x-1]+lb[y-1]-c
	if mi > z:
		mi=z
print(mi)

Submission status: Accepted

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

import sys
from collections import deque as deq

An, Bn, Mn = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
M = [list(map(int, input().split())) for i in range(Mn)]

mia = 10**5 + 10**5
for a in A:
    mia = a if a < mia else mia

mib = 10**5 + 10**5
for b in B:
    mib = b if b < mib else mib

R = mia + mib
for m in M:
    c = A[m[0] - 1] + B[m[1] - 1] - m[2]
    R = c if c < R else R

print(R)

Submission status: Accepted

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

mincomb = min(a) + min(b)

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

print(mincomb)

Submission status: Accepted

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

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


min_defo = min(a)+min(b)
min_discount = min(price)

print(min(min_defo,min_discount))

Submission status: Accepted

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


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

    if v < min_v:
        min_v = v

min_pair = min(a_i) + min(b_i)

if min_pair < min_v:
    min_v = min_pair

print(min_v)

Submission status: Accepted

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):
    j,k,l = map(int, input().split())
    x.append(j)
    y.append(k)
    c.append(l)
    

min_buy = min(a)+min(b)

for i in range(M):
    price = a[x[i]-1] + b[y[i]-1] - c[i]
    if min_buy > price:
        min_buy = price
        
print(min_buy)

Submission status: Accepted

Solution code:
A,B,M=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
L=[list(map(int,input().split())) for i in range(M)]
x=[]
y=[]
c=[]
for i in range(M):
    x.append(L[i][0])
    y.append(L[i][1])
    c.append(L[i][2])
La=min(a)
Lb=min(b)
ans=La+Lb
for i in range(M):
    X=x[i]-1
    Y=y[i]-1
    han=a[X]+b[Y]-c[i]
    ans=min(han,ans)
print(ans)

Submission status: Accepted

Solution code:
a,b,m = map(int,input().split())
ap = list(map(int,input().split()))
bp = list(map(int,input().split()))
ls = []
for i in range(m):
    ls.append(list(map(int,input().split())))
m = min(ap)+min(bp)

for x,y,c in ls:
    if m > ap[x-1] + bp[y-1] - c:
        m =  ap[x-1] + bp[y-1] - c
print(m)

Submission status: Accepted

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

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

ans = min(reizouko_list) + min(densi_list)

for x, y, c in waribiki_list:
    value = reizouko_list[x - 1] + densi_list[y - 1] - c
    if ans > value:
        ans = value
print(ans)

Submission status: Accepted

Solution code:
a, b, m = map(int, input().split())
alist = list(map(int, input().split()))
blist = list(map(int, input().split()))
waribiki = [list(map(int, input().split())) for i in range(m)]
ans = min(alist) + min(blist)
for i in range(m):
    if ans > alist[waribiki[i][0] - 1] + blist[waribiki[i][1] - 1] - waribiki[i][2]:
        ans = alist[waribiki[i][0] - 1] + blist[waribiki[i][1] - 1] - waribiki[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()))
x=[0]*M
y=[0]*M
c=[0]*M
for i in range(M):
    x[i],y[i],c[i]=map(int,input().split())
#print(A,B,M,a,b,x,y,c)

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

print(mins)

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

Submission status: Accepted

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()] 
xyc = [input().split() for k in range(M)]
ans = []


for i in range(M):
  ans.append(a[int(xyc[i][0])-1] + b[int(xyc[i][1])-1]-int(xyc[i][2]))
  
ans.sort()
a.sort()
b.sort()
nomin=a[0]+b[0]

print(min(ans[0],nomin))

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

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

#Not discount
Nd = min(a) + min(b)

#discount
out = Nd
for i in range(M):
    d = a[xyc[i][0] -1] + b[xyc[i][1] -1] - xyc[i][2]
    if d < out:
        out=d

print(out)

Submission status: Accepted

Solution code:
n_a, n_b, n_m = map(int, input().split())

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

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

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

print(min(price))

Submission status: Accepted

Solution code:
a, b, m = input().split(' ')
m = int(m)
reizouko_list = [int(n) for n in input().split(' ')]
renji_list    = [int(n) for n in input().split(' ')]
yasui = min(reizouko_list) + min(renji_list)

for i in range(m):
  x, y, c = input().split(' ')
  x = int(x) - 1
  y = int(y) - 1
  c = int(c)
  if reizouko_list[x] + renji_list[y] - c < yasui:
    yasui = reizouko_list[x] + renji_list[y] - c
print(yasui)

Submission status: Accepted

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

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

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)
temp = 0

for i in range(m):
  x,y,c =  map(int,input().split())
  temp = al[x-1] + bl[y-1] - c
  if temp < ans:
    ans = temp
print(ans)

Submission status: Accepted

Solution code:
a,b,m=map(int,input().split())
cooler=list(map(int,input().split()))
microwave=list(map(int,input().split()))
min_price=min(cooler)+min(microwave)
for i in range(m):
    x,y,c=map(int,input().split())
    min_price=min(min_price,cooler[x-1]+microwave[y-1]-c)
print(min_price)

Submission status: Accepted

Solution code:
a,b,m=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
R=[]
for i in range(0,m):
  t=input()
  x=int((t.split())[0])
  y=int((t.split())[1])
  c=int((t.split())[2])
  R.append(A[x-1]+B[y-1]-c)
r=min((min(A)+min(B)),min(R))
print(r)

Submission status: Accepted

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

As = list(map(int, input().split()))
Bs = list(map(int, input().split()))

z = []
result = min(As) + min(Bs)

for _ in range(M):
    a, b, m = map(int, input().split())
    k = As[a - 1] + Bs[b - 1] - m
    if result > k:
        result = k

print(result)

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)
for l in sys.stdin:
  xi,yi,ci = map(int,l.split())
  ans = min(ans,a[xi-1]+b[yi-1]-ci)
print(ans)

Submission status: Accepted

Solution code:
import numpy as np

def resolve():
    A, B, M = map(int, input().split())
    al = list(map(int, input().split()))
    bl = list(map(int, input().split()))
    xyc = [list(map(int, input().split())) for _ in range(M)]
    #print(xyc)

    # 割引なしの状態での最小の組み合わせ
    i_no = np.argmin(al)
    j_no = np.argmin(bl)
    v_no= al[i_no] + bl[j_no]

    #print(i_no, j_no, v_no)

    v_min = v_no
    for c in xyc:
        v = al[c[0]-1] + bl[c[1]-1] - c[2]
        if v < v_min:
            v_min = v

    print(v_min)

if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
#At coder 2020/3/9 B
#import math
#import time
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 ii in range(M):
    x,y,c=list(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 = 10**8
for i in range(m):
    x,y,c = map(int,input().split())
    x-= 1
    y -=1
    ans = min(ans,a[x]+ b[y]-c)
a.sort()
b.sort()
ans = min(ans,a[0] + b[0])
print(ans)

Submission status: Accepted

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

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

    print(ans)


main()

Submission status: Accepted

Solution code:
A,B,M = map(int,input().split())
Ai = list(map(int,input().split()))
Bi = list(map(int,input().split()))
amin = min(Ai)
bmin= min(Bi)
min = amin+bmin
for i in range(M):
	xi,yi,ci = map(int,input().split())
	if Ai[xi-1] + Bi[yi-1] - ci < min:
		min = Ai[xi-1] + Bi[yi-1] - ci
print(min)

Submission status: Accepted

Solution code:
input_line = [int(i) for i in input().split()]
a = input_line[0]
b = input_line[1]
m = input_line[2]

a_list = [int(i) for i in input().split()]
b_list = [int(i) for i in input().split()]

discount = []
for i in range(m):
    input_line = [int(j) for j in input().split()]
    a_i = input_line[0] - 1
    b_i = input_line[1] - 1
    c = input_line[2]
    discount.append([a_i, b_i, c])

min_price = min(a_list) + min(b_list)
for i in discount:
    discount_price = a_list[i[0]] + b_list[i[1]] - i[2]
    if min_price > discount_price:
        min_price = discount_price
print(min_price)

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline
a,b,m=map(int,input().split())
a_list=list(map(int,input().split()))
b_list=list(map(int,input().split()))
ans=10**9
for i in range(m):
    x,y,c=map(int,input().split())
    ans=min(ans,a_list[x-1]+b_list[y-1]-c)
ans=min(ans,min(a_list)+min(b_list))
print(ans)

Submission status: Accepted

Solution code:
a,b,m = map(int,input().split())
la = list(map(int,input().split()))
lb = list(map(int,input().split()))
s = min(la) + min(lb)

for i in range (m):
    x,y,c = map(int,input().split())
    t = la[x-1]+lb[y-1]-c
    if t < s:
        s = t
    else:
        s = s

print (s)

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)

for s in sys.stdin:
    x,y,c = map(int, s.split())
    tmp = a[x-1] + b[y-1] - c
    ans = min(ans, tmp)
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()))
lst=[]
for i in range(m):
  x,y,c=map(int,input().split())
  lst.append([x,y,c])
v=min(A)+min(B)
for i in range(m):
  V=A[lst[i][0]-1]+B[lst[i][1]-1]-lst[i][2]
  if v>V:
    v=V
print(v)

Submission status: Accepted

Solution code:
a,b,m = map(int,input().split())
a_list = list(map(int,input().split()))
b_list = list(map(int,input().split()))
a_min = min(a_list)
b_min = min(b_list)
ans = a_min + b_min

for i in range(m):
    x,y,z = map(int,input().split())
    if a_list[x-1] + b_list[y-1] - z < ans:
        ans = a_list[x-1] + b_list[y-1] - z
        
print(ans)

Submission status: Accepted

Solution code:
A,B,M = map(int,input().split(" "))
F = [int(i) for i in input().split(" ")]
O = [int(j) for j in input().split(" ")]

Min = min(F) + min(O)
for i in range(M):
    x,y,c = map(int,input().split(" "))
    f = F[x-1]
    o = O[y-1]
    C = f+o-c
    if C<Min:
        Min = C
print(Min)

Submission status: Accepted

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

min_price = min(a_list) + min(b_list)
for i in range(m):
    x, y, c = map(int, input().split())
    val = a_list[x-1] + b_list[y-1] - c
    if min_price > val:
        min_price = val

print(min_price)

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

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

nedan = min(a)+min(b)
for j in range(M):
    nedan = min(nedan,a[m[j][0]-1]+b[m[j][1]-1]-m[j][2])

print(nedan)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
 
import math
import itertools
import sys
import copy
#import numpy as np
 
# 入力
#A, B, C, D = map(int, input().split())
#L = list(map(int, input().split()))
#S = list(str(input()))
#N = int(input())
#S = str(input())

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

#割引券を使う場合
ans = sys.maxsize
for _ in range(M) :
  x, y, c = map(int, input().split())
  ans = min(ans, a[x-1]+b[y-1]-c)

#その他の組み合わせ
ans = min(ans, min(a)+min(b))

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

min_price = min(a) + min(b)

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

print(min_price)