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:
# n, m, l = map(int, input().split())

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

# n = input()
# list = [input() for i in range(N)

# list = [[i for i in range(N)] for _ in range(M)]

import sys
input = sys.stdin.readline

A, B, M = map(int, input().split())
List_A = list(map(int, input().split()))
List_B = list(map(int, input().split()))
List_discount = [list(map(int, input().split())) for i in range(M)]

# print(List_discount)
ans = 2 * 10**5
for d in List_discount:
    # print(d)
    p = List_A[d[0]-1] + List_B[d[1]-1] - d[2]
    ans = min(ans, p)
no_discount = min(List_A) + min(List_B)
ans = min(ans, no_discount)
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()))
discount = list(map(int, input().split()) for _ in range(M))

ans = min(a) + min(b)

for x, y, c in discount:
    tmp = a[x - 1] + b[y - 1] - c
    if tmp < ans:
        ans = tmp

print(ans)

Submission status: Accepted

Solution code:
A, B, M = map(int, input().split())
Frz = list(map(int, input().split()))
Mic = list(map(int, input().split()))
C = []

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

minF = min(Frz)
minM = min(Mic)
ans = minF + minM

for x, y, z in C:
    tmp = Frz[x] + Mic[y] - z
    if tmp < ans:
        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()))
res = min(a) + min(b)
for _ in range(M):
    x, y, c = map(int, input().split())
    res = min(res, a[x-1] + b[y-1] - c)
print(res)

Submission status: Accepted

Solution code:
a,b,m=map(int,input().split())
f=list(map(int,input().split()))
w=list(map(int,input().split()))
money=min(f)+min(w)
for i in range(m):
    x,y,c=map(int,input().split())
    if f[x-1]+w[y-1]-c<money:
        money=f[x-1]+w[y-1]-c
print(money)

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

Submission status: Accepted

Solution code:
A,B,M=map(int,input().split())
a=[int(x) for x in input().split()]
b=[int(x) for x in input().split()]
m=[[] for i in range(M)]
for i in range(M):
  m[i]=[int(x) for x in input().split()]
  
for i in range(M):
  m[i]=a[m[i][0]-1]+b[m[i][1]-1]-m[i][2]
if(min(m)>min(a)+min(b)):
  print(min(a)+min(b))
else:
  print(min(m))

Submission status: Accepted

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

print(min(min(ans),yasuiyo))

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

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

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.read
def main():
    a, b, m = map(int, input().split())
    al = tuple(map(int, input().split()))
    bl = tuple(map(int, input().split()))
    r = min(al) + min(bl)
    m = map(int, read().split())
    xyc = zip(m, m, m)
    for x, y, c in xyc:
        r = min(r, al[x-1] + bl[y-1] - c)
    print(r)

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

e=min(a)+min(b)

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

print(e)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a, b, m = map(int, input().split())
reizo = list(map(int, input().split()))
renji = list(map(int, input().split()))
p = [list(map(int,input().split())) for i in range(m)]
ans = []
for i in range(m):
  cost = reizo[p[i][0] - 1] + renji[p[i][1] - 1] - p[i][2]
  ans.append(cost)
ans.append(min(reizo) + min(renji))
print(min(ans))

Submission status: Accepted

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

Submission status: Accepted

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

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

print(r)

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=min(A)+min(B)
for i in range(m):
  x,y,c=map(int,input().split())
  r=min(r,A[x-1]+B[y-1]-c)

print(r)

Submission status: Accepted

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

ans = min(lista)+min(listb)

for i in range(m):
    x, y, c = map(int, input().split())
    dprice = lista[x-1]+listb[y-1] - c
    if ans > dprice:
        ans = dprice

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**6
for i in range(M):
    x,y,c=map(int,input().split())
    ans=min(ans,(a[x-1]+b[y-1])-c)
a.sort(key=int)
b.sort(key=int)
for i in range(min(A,B)):
    if a[i]+b[i]>=ans: break
    ans=min(ans,a[i]+b[i])
print(ans)

Submission status: Accepted

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

A = [0] + A
B = [0] + B


X = [[] for _ in range(M)]
Y = [[] for _ in range(M)]
C = [[] for _ in range(M)]

for i in range(M):
    X[i], Y[i], C[i] = map(int, input().split())

# indipendent
ans1 = min(A[1:]) + min(B[1:])

# set
ans2 = max(A) + max(B)
for x, y, c in zip(X, Y, C):
    ans2 = min(ans2, A[x] + B[y] - c)

print(min(ans1, ans2))

Submission status: Accepted

Solution code:
# template by 3xC and starkizard.
# contributors: 

#####################################################################################
from __future__ import division, print_function 

import sys
import os
from collections import Counter, deque, defaultdict
import itertools
import math
import io


"""Uncomment modules according to your need"""


# from bisect import bisect_left, bisect_right, insort
# from heapq import heappop, heapify, heappush
# from random import randint as rn
# from Queue import Queue as Q
# from copy import deepcopy
# from decimal import *
# import re
# import operator

#####################################################################################
# this enables you to write python3 code with PyPy2 (Python 2)
if sys.version_info[0] < 3:
    input = raw_input
    range = xrange

    filter = itertools.ifilter
    map = itertools.imap
    zip = itertools.izip

#####################################################################################

"""value of mod"""
MOD = 998244353
mod = 10**9 + 7

"""Uncomment next 4 lines if doing huge recursion"""
# import threading
# threading.stack_size(1<<27)
# sys.setrecursionlimit(10000

def prepare_factorial(mod=mod):
    """ returns two lists, factorial and inverse factorial modulo argument by default 10**9 +7 """
    # Comment code out when you don't need inverse factorial or vice versa
    fact = [1]
    for i in range(1, 200005):
        fact.append((fact[-1] * i) % mod)

    ifact = [0] * 200005
    ifact[200004] = pow(fact[200004], mod - 2, mod)
    for i in range(200004, 0, -1):
        ifact[i - 1] = (i * ifact[i]) % mod

    return fact, ifact

def modinv(n, p):
    """ returns N inverse modulo p """
    return pow(n, p - 2, p)

def ncr(n, r,  fact, ifact):
    """ takes 4 arguments: n , r and factorial and inverse factorial lists"""
    t = (fact[n] * (ifact[r]*ifact[n-r]) % MOD)% MOD
    return t


def get_n(Sum):    
    """this function returns the maximum n for which Summation(n) <= Sum"""
    ans = (-1 + sqrt(1 + 8*Sum))//2
    return ans

def sieve(n):
    """ returns a list of prime numbers till n """
    if n < 2: return list()
    prime = [True for _ in range(n + 1)]
    p = 3
    while p * p <= n:
        if prime[p]:
            for i in range(p * 2, n + 1, p):
                prime[i] = False
        p += 2
    r = [2]
    for p in range(3, n + 1, 2):
        if prime[p]:
            r.append(p)
    return r



def divs(n, start=1):
    """ returns a list of all divisors till n """
    divisors = []
    for i in range(start, int(math.sqrt(n) + 1)):
        if n % i == 0:
            if n / i == i:
                divisors.append(i)
            else:
                divisors.extend([i, n // i])
    return divisors



def divn(n, primes):
    """ returns the number of divisors, two arguments n and the sieve till n """
    divs_number = 1
    for i in primes:
        if n == 1:
            return divs_number
        t = 1
        while n % i == 0:
            t += 1
            n //= i
        divs_number *= t



def lrfind(d, x, default=-1):
    """ Takes 2 arguments an iterable and an element. returns a tuple (firstoccurence,lastoccurence) -1 if not found """
    left = right = -1
    for i in range(len(d)):
        if d[i] == x:
            if left == -1: left = i
            right = i
    if left == -1:
        return default, default
    else:
        return left, right

def gcd(x, y): # math.gcd is slower
    """ returns greatest common divisor of x and y """
    while y:
        x, y = y, x % y
    return x

def check_sorted(a):
    ''' returns True/False '''
    for i in range(len(a)-1):
        if a[i]>a[i+1]:
            return False
    return True
def ceil(n, k=1): return n // k + (n % k != 0) #returns math.ceil but protecting against floating inconsistencies
def input(): return sys.stdin.readline().strip()
def ii(): return int(input()) #inputs integer
def mi(): return map(int, input().split()) # inputting space seperated variables for example x,y,z
def li(): return list(map(int, input().split())) #inputting a space seperated list of integers
def lw(): return input().split() #inputting a space seperated list of strings
def lcm(a, b): return abs(a * b) // gcd(a, b) #returns LCM of two arguments
def prr(a, sep=' ', end='\n'): print(sep.join(map(str, a)), end=end) #For printing an iterable with seperator sep as optional second argument (default : " "), ending character (default: "\n") as optional third
def dd(): return defaultdict(int) #returns a dictionary with values defaulted to 0
def ddl(): return defaultdict(list) #returns a dictionary with values defaulted to []
def write(s): return sys.stdout.write(s)












###################################################################
def main():
    #CODE GOES HERE:
    A,B,M=mi()
    a=li()
    b=li()
    answer=min(a)+min(b)
    for i in range(M):
        x,y,c=mi()
        answer=min(answer,a[x-1]+b[y-1]-c) 
    print(answer)   

















    
""" -------- Python 2 and 3 footer by Pajenegod and c1729 ---------"""

py2 = round(0.5)
if py2:
    from future_builtins import ascii, filter, hex, map, oct, zip
    range = xrange

import os, sys
from io import IOBase, BytesIO

BUFSIZE = 8192

class FastIO(BytesIO):
    newlines = 0

    def __init__(self, file):
        self._file = file
        self._fd = file.fileno()
        self.writable = "x" in file.mode or "w" in file.mode
        self.write = super(FastIO, self).write if self.writable else None

    def _fill(self):
        s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
        self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
        return s

    def read(self):
        while self._fill(): pass
        return super(FastIO, self).read()

    def readline(self):
        while self.newlines == 0:
            s = self._fill();
            self.newlines = s.count(b"\n") + (not s)
        self.newlines -= 1
        return super(FastIO, self).readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.getvalue())
            self.truncate(0), self.seek(0)


class IOWrapper(IOBase):

    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        if py2:
            self.write = self.buffer.write
            self.read = self.buffer.read
            self.readline = self.buffer.readline
        else:
            self.write = lambda s: self.buffer.write(s.encode('ascii'))
            self.read = lambda: self.buffer.read().decode('ascii')
            self.readline = lambda: self.buffer.readline().decode('ascii')


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip('\r\n')
# sys.stdin = open('input.txt', 'r')
# sys.stdout = open('output.txt', 'w')

""" main function"""

if __name__ == '__main__':
    main()
    # threading.Thread(target=main).start()

Submission status: Accepted

Solution code:
A, B, M = map(int, input().split())
lis_a = list(map(int, input().split()))
lis_b = list(map(int, input().split()))
lis_price = []

lis_price.append(min(lis_a) + min(lis_b))

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

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

a_m = min(a)
b_m = min(b)
ans = a_m + b_m

for i in range(m):
    a_i = xyc[i][0] - 1
    b_i = xyc[i][1] - 1
    c_i = xyc[i][2]
    pri = a[a_i] + b[b_i] - c_i
    ans = min(ans,pri)

print(ans)

Submission status: Accepted

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

ans = min(A) + min(B)

for c in C:
    if (A[c[0]-1]+B[c[1]-1]-c[2])<ans:
        ans = A[c[0]-1]+B[c[1]-1]-c[2]
print(ans)

Submission status: Accepted

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

ans = min(pa) + min(pb)
for _ in range(m):
    x, y, c = map(int, input().split())
    x -= 1
    y -= 1
    ans = min(ans, pa[x] + pb[y] - c)

print(ans)

Submission status: Accepted

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

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

print( min(min(a) + min(b),  min( [a[i[0]-1] + b[i[1]-1] - i[2] for i in mlist ])))

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

lis=[min(A)+min(B)]

for i in range(m):
    lis.append(A[C[i][0]-1]+B[C[i][1]-1]-C[i][2])

print(min(lis))

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 = 0
lpr = min(a) + min(b)
dcp = []

for i in range(M):
    indexA = xyc[i][0] - 1
    indexB = xyc[i][1] - 1
    dcp.append(a[indexA] + b[indexB] - xyc[i][2])

ans = min(min(dcp), lpr)
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 = []
for i in range(m):
    x.append(list(map(int, input().split())))

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

for i in range(m):
    kingaku = a[x[i][0]-1] + b[x[i][1]-1] - x[i][2]
    if kingaku < money:
        money = kingaku

print(money)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip()

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

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

Submission status: Accepted

Solution code:
a_b_m_var = input().split()
a_i_var = input().split()
b_i_var = input().split()

a_b_m = [int(s) for s in a_b_m_var]
a_i = [int(s) for s in a_i_var]
b_i = [int(s) for s in b_i_var]

not_discount_price = min(a_i) + min(b_i)

down_price_i = []
for i in range(a_b_m[2]):
    price_down_var = input().split()
    price_down = [int(s) for s in price_down_var]
    a, b, m = price_down[0], price_down[1], price_down[2]
    price = a_i[a-1] + b_i[b-1] - m
    down_price_i.append(price)

if not_discount_price > min(down_price_i):
    print(min(down_price_i))
else:
    print(not_discount_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()))

ans=min(a)+min(b)

for i in range(m):
    p,q,r=map(int,input().split())
    ans=min(a[p-1]+b[q-1]-r,ans)
print(ans)

Submission status: Accepted

Solution code:
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
d = [list(map(int, input().split())) for i in range(a[2])]
e = [min(b) + min(c)]
for f in d:
  e.append(b[f[0] - 1] + c[f[1] - 1] - f[2])
print(min(e))

Submission status: Accepted

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

res = 10**6

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

a.sort()
b.sort()
print(min(res, a[0]+b[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()))
m=[list(map(int,input().split())) for _ in range(M)]
min_a=min(a)
min_b=min(b)

min_cost=min_a+min_b
for _m in m:
  cost=a[_m[0]-1]+b[_m[1]-1]-_m[2]
  min_cost=min(min_cost,cost)
print(min_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()))
minimum = min(a)+min(b)
for _ in range(M):
    x, y, c = map(int, input().split())
    minimum = min(a[x-1]+b[y-1]-c, minimum)
print(minimum)

Submission status: Accepted

Solution code:
def main():
    a, b, m = map(int, input().split())
    
    # 冷蔵庫
    f_list = list(map(int, input().split()))
    # 電子レンジ
    m_list = list(map(int, input().split()))
    # 割引券
    t_list = [list(map(int, input().split())) for _ in range(m)]
    # 金額
    p_list = []
    
    
    p_list.append(min(f_list) + min(m_list))
    for t in t_list:
        p_list.append(f_list[t[0]-1] + m_list[t[1]-1] - t[2])
    
    ans = min(p_list)
    print(ans)
    

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

    a.sort()
    b.sort()
    dis.sort()
    ans = min(a[0] + b[0], dis[0])
    print(ans)

    return


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()))
li = [list(map(int,input().split())) for i in range(m)]
kouho = [min(a)+min(b)]

for l in li:
    kouho.append(a[l[0]-1] + b[l[1]-1] -l[2])

print(min(kouho))

Submission status: Accepted

Solution code:
if __name__ == '__main__':
   a, b, n = map(int, input().split())
   lista =  [int(i) for i in input().split()]
   listb =  [int(i) for i in input().split()]
   minP = min(lista) + min(listb)

   for i in range(n):
       c = [int(i) for i in input().split()]
       now =lista[c[0]-1] + listb[c[1]-1] - c[2]
       if  now< minP :
           minP=now

   print(minP)

Submission status: Accepted

Solution code:
A,B,M=map(int,input().split())
at=list(map(int,input().split()))
bt=list(map(int,input().split()))
xyc=[list(map(int,input().split())) for i in range(M)]

minc=min(at)+min(bt)

for i in range(M):
    minc=min(minc,at[xyc[i][0]-1]+bt[xyc[i][1]-1]-xyc[i][2])
    
print(minc)

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 = []
y = []
c = []
for _ in range(M):
    xt, yt, ct = [int(x) for x in input().split()]
    x.append(xt)
    y.append(yt)
    c.append(ct)

# 割引券を使わない場合の最小値
ret = min(a) + min(b)

# 割引券を使った場合
for i in range(len(x)):
    t = a[x[i] - 1] + b[y[i] - 1] - c[i]
    if ret > t:
        ret = t

print(ret)

Submission status: Accepted

Solution code:
a,b,m=map(int,input().split())
ali= list(map(int,input().split()))	
bli= list(map(int,input().split()))	
min=min(ali)+min(bli)
for i in range(0,m):
  x,y,c=map(int,input().split())
  mon=ali[x-1]+bli[y-1]-c
  if mon<min:
    min=mon
    
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(" ")))
res = min(a) + min(b)
for _ in range(M):
    x,y, c = list(map(int,input().split(" ")))
    x-=1
    y-=1
    res = min(res,a[x]+b[y]-c)
print(res)

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**6

for i 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:
import sys
input = sys.stdin.readline

def main():
    A, B, M = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    ans = 10**6

    for i 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)

main()

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

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 = map(int, input().split())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
X = []
Y = []
C = []
for i in range(m):
    x, y, c = [int(j) for j in input().split()]
    X.append(x)
    Y.append(y)
    C.append(c)
# print(X, Y, C)

pricelist = [min(A) + min(B)]
for i in range(m):
    pricelist.append(A[X[i]-1] + B[Y[i]-1] - C[i])
print(min(pricelist))

Submission status: Accepted

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

# In[9]:


A,B,M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
mylist = []
for _ in range(M):
    mylist.append(list(map(int, input().split())))


# In[11]:


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


# In[ ]:

Submission status: Accepted

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

payl = []
nom = min(al) + min(bl)
payl.append(nom)

for i in range(m):
    ml = list(map(int, input().split()))
    payl.append(al[ml[0] - 1] + bl[ml[1] - 1] - ml[2])

print(min(payl))

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

Submission status: Accepted

Solution code:
(a,b,m),x,y,*c=[list(map(int, i.split())) for i in open(0)]
print(min([x[~-i]+y[~-j]-k for i,j,k in c]+[min(x)+min(y)]))

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_refrigerator = min(a)
    min_microwave = min(b)
    not_use_coupon = min_refrigerator + min_microwave

    max_sale = max(c)
    use_coupon = 2000000
    for xi, yi, ci in zip(x, y, c):
        use_coupon = min(use_coupon, a[xi - 1] + b[yi - 1] - ci)

    ans = min(use_coupon, not_use_coupon)
    print(ans)
    return


# Generated by 1.1.7.1 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

input = sys.stdin.readline


def main():
    A, B, M = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    xyc = [0] * M
    for i in range(M):
        xyc[i] = map(int, input().split())

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

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
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)