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: Runtime Error

Solution code:

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

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

ans = min(a) + min (b)

for i in range(m):
    keep = a[c[i][0]-1] + b[c[i][1]-1] - c[i][2]
    if keep < ans:
        ans = keep

print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
from collections import defaultdict
import numpy as np

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

C = defaultdict(int)

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

ans = a.min() + b.min()

for c in C:
    ans = min(ans, a[c[0]] + b[c[0]] - C[c])
    
print(ans)

Submission status: Runtime Error

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):
    c =list(map(int,input().split()))
    s = a[c[0]-1]+b[c[1]-1]-c[2]
    min = min(s,min)

print(min)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
A, B, M = map(int, input().split())
Fre = list(map(int, input().split()))
Mic = list(map(int, input().split()))
Tic = []
Price = 10**5
for i in range(M):
  Tic.append(list(map(int, input().split())))
print(A,B,M,Fre,Mic,Tic)

for i in range(A):
  for j in range(B):
    n = Fre[i] + Mic[j]
    if n < Price:
      Price = n
for i in range(1, len(Tic)):
  n = Fre[Tic[i][0]] + Mic[Tic[i][1]] - Tic[i][2]
  if n < Price:
    Price = n
print(Price)

Submission status: Runtime Error

Solution code:
import sys
from io import StringIO
import unittest

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """2 3 1
3 3
3 3 3
1 2 1"""
        output = """5"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """1 1 2
10
10
1 1 5
1 1 10"""
        output = """10"""
        self.assertIO(input, output)
    def test_入力例_3(self):
        input = """2 2 1
3 5
3 5
2 2 2"""
        output = """6"""
        self.assertIO(input, output)

if __name__ == "__main__":
    unittest.main()

Submission status: Runtime Error

Solution code:
A,B,M=map(int,input().split())
a_1=list(map(int,input().split()))
b_1=list(map(int,input().split()))
L=[list(map(int,input().split())) for _ in range(M)]

count=[]
for i in a_1:
    for j in b_1:
        count.append(i+j)

for k in range(M):
    count.append(a_1[L[k][0]]+b_1[L[k][1]]-L[k][2])

print(min(count))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
#入力処理
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
kingaku=[]
for i in range(M):
    x_input, y_input, c_input = map(int, input().split())
    kingaku.append(a[x_input-1][y_input-1]+b[x_input-1][y_input-1]+c_input)
kingaku.append(min(a)+min(b))

print(min(kingaku))

Submission status: Runtime Error

Solution code:
import sys

A, B, M = map(int, sys.stdin.readline().rstrip().split())
a = list(map(int, sys.stdin.readline().rstrip().split()))
b = list(map(int, sys.stdin.readline().rstrip().split()))
xyc = [list(map(int, sys.stdin.readline().rstrip().split())) for i in range(M)]
mans = min(a) + min(b)
ans = mans
for xyci in xyc:
    tmp = a[xyci[0] - 1] + a[xyci[1] - 1] - xyci[2]
    if ans > tmp:
        ans = tmp

print(ans)

Submission status: Runtime Error

Solution code:
import sys

A, B, M = map(int, sys.stdin.readline().rstrip().split())
a = list(map(int, sys.stdin.readline().rstrip().split()))
b = list(map(int, sys.stdin.readline().rstrip().split()))
xyc = [list(map(int, sys.stdin.readline().rstrip().split())) for i in range(M)]
ans = 10 ** 9 + 7
mans = min(a) + min(b)
for xyci in xyc:
    tmp = a[xyci[0] - 1] + a[xyci[1] - 1] - xyci[2]
    if ans > tmp:
        ans = tmp

print(min(tmp, mans))

Submission status: Runtime Error

Solution code:
# coding: utf-8
import re
import math
import itertools
from copy import deepcopy
import random
from heapq import heappop,heappush
import time
import os
import queue
import sys
import datetime
from functools import lru_cache
readline=sys.stdin.readline
sys.setrecursionlimit(2000)
#import numpy as np
alphabet="abcdefghijklmnopqrstuvwxyz"
mod=int(10**9+7)
inf=int(10**20)
week=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]
def yn(b):
    if b:
        print("yes")
    else:
        print("no")
def Yn(b):
    if b:
        print("Yes")
    else:
        print("No")
def YN(b):
    if b:
        print("YES")
    else:
        print("NO")
class union_find():
    def __init__(self,n):
        self.n=n
        self.P=[a for a in range(N)]
        self.rank=[0]*n
 
    def find(self,x):
        if(x!=self.P[x]):self.P[x]=self.find(self.P[x])
        return self.P[x]
 
    def same(self,x,y):
        return self.find(x)==self.find(y)
 
    def link(self,x,y):
        if self.rank[x]<self.rank[y]:
            self.P[x]=y
        elif self.rank[y]<self.rank[x]:
            self.P[y]=x
        else:
            self.P[x]=y
            self.rank[y]+=1
 
    def unite(self,x,y):
        self.link(self.find(x),self.find(y))
 
    def size(self):
        S=set()
        for a in range(self.n):
            S.add(self.find(a))
        return len(S)
def is_power(a,b):#aはbの累乗数か
    now=b
    while now<a:
        now*=b
    if now==a:return True
    else:return False
def bin_(num,size):
    A=[0]*size
    for a in range(size):
        if (num>>(size-a-1))&1==1:
            A[a]=1
        else:
            A[a]=0
    return A
def facs(n,mod_=0):
    A=[1]*(n+1)
    for a in range(2,len(A)):
        A[a]=A[a-1]*a
        if(mod_>0):A[a]%=mod_
    return A
def comb(n,r,mod_,fac):
    if(n-r<0):return 0
    return (fac[n]*pow(fac[n-r],mod_-2,mod_)*pow(fac[r],mod_-2,mod_))%mod_
def next_comb(num,size):
    x=num&(-num)
    y=num+x
    z=num&(~y)
    z//=x
    z=z>>1
    num=(y|z)
    if(num>=(1<<size)):return False
    else:
        return num
def get_primes(n,type="int"):
    A=[True]*(n+1)
    A[0]=False
    A[1]=False
    for a in range(2,n+1):
        if A[a]:
            for b in range(a*2,n+1,a):
                A[b]=False
    if(type=="bool"):return A
    B=[]
    for a in range(n+1):
        if(A[a]):B.append(a)
    return B
def is_prime(num):
    if(num<=2):return False
    i=2
    while i*i<=num:
       if(num%i==0):return False
       i+=1
    return True
def ifelse(a,b,c):
    if a:return b
    else:return  c
def join(A,c=" "):
    n=len(A)
    A=list(map(str,A))
    s=""
    for a in range(n):
        s+=A[a]
        if(a<n-1):s+=c
    return s
def factorize(n,type_="dict"):
    b = 2
    list_ = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            list_.append(b)
        b+=1
    if n > 1:list_.append(n)
    if type_=="dict":
        dic={}
        for a in list_:
            if a in dic:
                dic[a]+=1
            else:
                dic[a]=1
        return dic
    elif type_=="list":
        return list_
    else:
        return None
def floor_(n,x=1):
    return x*(n//x)
def ceil_(n,x=1):
    return x*((n+x-1)//x)
#################################### ########
# coding: utf-8
import re
import math
import itertools
from copy import deepcopy
import random
from heapq import heappop,heappush
import time
import os
import queue
import sys
import datetime
from functools import lru_cache
readline=sys.stdin.readline
sys.setrecursionlimit(2000)
#import numpy as np
alphabet="abcdefghijklmnopqrstuvwxyz"
mod=int(10**9+7)
inf=int(10**20)
def yn(b):
    if b:
        print("yes")
    else:
        print("no")
def Yn(b):
    if b:
        print("Yes")
    else:
        print("No")
def YN(b):
    if b:
        print("YES")
    else:
        print("NO")
class union_find():
    def __init__(self,n):
        self.n=n
        self.P=[a for a in range(N)]
        self.rank=[0]*n
 
    def find(self,x):
        if(x!=self.P[x]):self.P[x]=self.find(self.P[x])
        return self.P[x]
 
    def same(self,x,y):
        return self.find(x)==self.find(y)
 
    def link(self,x,y):
        if self.rank[x]<self.rank[y]:
            self.P[x]=y
        elif self.rank[y]<self.rank[x]:
            self.P[y]=x
        else:
            self.P[x]=y
            self.rank[y]+=1
 
    def unite(self,x,y):
        self.link(self.find(x),self.find(y))
 
    def size(self):
        S=set()
        for a in range(self.n):
            S.add(self.find(a))
        return len(S)
def is_power(a,b):#aはbの累乗数か
    now=b
    while now<a:
        now*=b
    if now==a:return True
    else:return False
def bin_(num,size):
    A=[0]*size
    for a in range(size):
        if (num>>(size-a-1))&1==1:
            A[a]=1
        else:
            A[a]=0
    return A
def get_facs(n,mod_=0):
    A=[1]*(n+1)
    for a in range(2,len(A)):
        A[a]=A[a-1]*a
        if(mod>0):A[a]%=mod_
    return A
def comb(n,r,mod,fac):
    if(n-r<0):return 0
    return (fac[n]*pow(fac[n-r],mod-2,mod)*pow(fac[r],mod-2,mod))%mod
def next_comb(num,size):
    x=num&(-num)
    y=num+x
    z=num&(~y)
    z//=x
    z=z>>1
    num=(y|z)
    if(num>=(1<<size)):return False
    else:
        return num
def get_primes(n,type="int"):
    A=[True]*(n+1)
    A[0]=False
    A[1]=False
    for a in range(2,n+1):
        if A[a]:
            for b in range(a*2,n+1,a):
                A[b]=False
    if(type=="bool"):return A
    B=[]
    for a in range(n+1):
        if(A[a]):B.append(a)
    return B
def is_prime(num):
    if(num<=2):return False
    i=2
    while i*i<=num:
       if(num%i==0):return False
       i+=1
    return True
def ifelse(a,b,c):
    if a:return b
    else:return  c
def join(A,c=" "):
    n=len(A)
    A=list(map(str,A))
    s=""
    for a in range(n):
        s+=A[a]
        if(a<n-1):s+=c
    return s
def factorize(n,type_="dict"):
    b = 2
    list_ = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            list_.append(b)
        b+=1
    if n > 1:list_.append(n)
    if type_=="dict":
        dic={}
        for a in list_:
            if a in dic:
                dic[a]+=1
            else:
                dic[a]=1
        return dic
    elif type_=="list":
        return list_
    else:
        return None
def floor_(n,x=1):
    return x*(n//x)
def ceil_(n,x=1):
    return x*((n+x-1)//x)
###################################################
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 _ in range(M):
        x,y,c=map(int,input().split())
        x-=1
        y-=1
        ans=min(ans,A[x]+A[y]-c)
    print(ans)


main()

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
# coding: utf-8
import re
import math
import itertools
from copy import deepcopy
import random
from heapq import heappop,heappush
import time
import os
import queue
import sys
import datetime
from functools import lru_cache
readline=sys.stdin.readline
sys.setrecursionlimit(2000)
#import numpy as np
alphabet="abcdefghijklmnopqrstuvwxyz"
mod=int(10**9+7)
inf=int(10**20)
week=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]
def yn(b):
    if b:
        print("yes")
    else:
        print("no")
def Yn(b):
    if b:
        print("Yes")
    else:
        print("No")
def YN(b):
    if b:
        print("YES")
    else:
        print("NO")
class union_find():
    def __init__(self,n):
        self.n=n
        self.P=[a for a in range(N)]
        self.rank=[0]*n
 
    def find(self,x):
        if(x!=self.P[x]):self.P[x]=self.find(self.P[x])
        return self.P[x]
 
    def same(self,x,y):
        return self.find(x)==self.find(y)
 
    def link(self,x,y):
        if self.rank[x]<self.rank[y]:
            self.P[x]=y
        elif self.rank[y]<self.rank[x]:
            self.P[y]=x
        else:
            self.P[x]=y
            self.rank[y]+=1
 
    def unite(self,x,y):
        self.link(self.find(x),self.find(y))
 
    def size(self):
        S=set()
        for a in range(self.n):
            S.add(self.find(a))
        return len(S)
def is_power(a,b):#aはbの累乗数か
    now=b
    while now<a:
        now*=b
    if now==a:return True
    else:return False
def bin_(num,size):
    A=[0]*size
    for a in range(size):
        if (num>>(size-a-1))&1==1:
            A[a]=1
        else:
            A[a]=0
    return A
def facs(n,mod_=0):
    A=[1]*(n+1)
    for a in range(2,len(A)):
        A[a]=A[a-1]*a
        if(mod_>0):A[a]%=mod_
    return A
def comb(n,r,mod_,fac):
    if(n-r<0):return 0
    return (fac[n]*pow(fac[n-r],mod_-2,mod_)*pow(fac[r],mod_-2,mod_))%mod_
def next_comb(num,size):
    x=num&(-num)
    y=num+x
    z=num&(~y)
    z//=x
    z=z>>1
    num=(y|z)
    if(num>=(1<<size)):return False
    else:
        return num
def get_primes(n,type="int"):
    A=[True]*(n+1)
    A[0]=False
    A[1]=False
    for a in range(2,n+1):
        if A[a]:
            for b in range(a*2,n+1,a):
                A[b]=False
    if(type=="bool"):return A
    B=[]
    for a in range(n+1):
        if(A[a]):B.append(a)
    return B
def is_prime(num):
    if(num<=2):return False
    i=2
    while i*i<=num:
       if(num%i==0):return False
       i+=1
    return True
def ifelse(a,b,c):
    if a:return b
    else:return  c
def join(A,c=" "):
    n=len(A)
    A=list(map(str,A))
    s=""
    for a in range(n):
        s+=A[a]
        if(a<n-1):s+=c
    return s
def factorize(n,type_="dict"):
    b = 2
    list_ = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            list_.append(b)
        b+=1
    if n > 1:list_.append(n)
    if type_=="dict":
        dic={}
        for a in list_:
            if a in dic:
                dic[a]+=1
            else:
                dic[a]=1
        return dic
    elif type_=="list":
        return list_
    else:
        return None
def floor_(n,x=1):
    return x*(n//x)
def ceil_(n,x=1):
    return x*((n+x-1)//x)
#################################### ########
# coding: utf-8
import re
import math
import itertools
from copy import deepcopy
import random
from heapq import heappop,heappush
import time
import os
import queue
import sys
import datetime
from functools import lru_cache
readline=sys.stdin.readline
sys.setrecursionlimit(2000)
#import numpy as np
alphabet="abcdefghijklmnopqrstuvwxyz"
mod=int(10**9+7)
inf=int(10**20)
def yn(b):
    if b:
        print("yes")
    else:
        print("no")
def Yn(b):
    if b:
        print("Yes")
    else:
        print("No")
def YN(b):
    if b:
        print("YES")
    else:
        print("NO")
class union_find():
    def __init__(self,n):
        self.n=n
        self.P=[a for a in range(N)]
        self.rank=[0]*n
 
    def find(self,x):
        if(x!=self.P[x]):self.P[x]=self.find(self.P[x])
        return self.P[x]
 
    def same(self,x,y):
        return self.find(x)==self.find(y)
 
    def link(self,x,y):
        if self.rank[x]<self.rank[y]:
            self.P[x]=y
        elif self.rank[y]<self.rank[x]:
            self.P[y]=x
        else:
            self.P[x]=y
            self.rank[y]+=1
 
    def unite(self,x,y):
        self.link(self.find(x),self.find(y))
 
    def size(self):
        S=set()
        for a in range(self.n):
            S.add(self.find(a))
        return len(S)
def is_power(a,b):#aはbの累乗数か
    now=b
    while now<a:
        now*=b
    if now==a:return True
    else:return False
def bin_(num,size):
    A=[0]*size
    for a in range(size):
        if (num>>(size-a-1))&1==1:
            A[a]=1
        else:
            A[a]=0
    return A
def get_facs(n,mod_=0):
    A=[1]*(n+1)
    for a in range(2,len(A)):
        A[a]=A[a-1]*a
        if(mod>0):A[a]%=mod_
    return A
def comb(n,r,mod,fac):
    if(n-r<0):return 0
    return (fac[n]*pow(fac[n-r],mod-2,mod)*pow(fac[r],mod-2,mod))%mod
def next_comb(num,size):
    x=num&(-num)
    y=num+x
    z=num&(~y)
    z//=x
    z=z>>1
    num=(y|z)
    if(num>=(1<<size)):return False
    else:
        return num
def get_primes(n,type="int"):
    A=[True]*(n+1)
    A[0]=False
    A[1]=False
    for a in range(2,n+1):
        if A[a]:
            for b in range(a*2,n+1,a):
                A[b]=False
    if(type=="bool"):return A
    B=[]
    for a in range(n+1):
        if(A[a]):B.append(a)
    return B
def is_prime(num):
    if(num<=2):return False
    i=2
    while i*i<=num:
       if(num%i==0):return False
       i+=1
    return True
def ifelse(a,b,c):
    if a:return b
    else:return  c
def join(A,c=" "):
    n=len(A)
    A=list(map(str,A))
    s=""
    for a in range(n):
        s+=A[a]
        if(a<n-1):s+=c
    return s
def factorize(n,type_="dict"):
    b = 2
    list_ = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            list_.append(b)
        b+=1
    if n > 1:list_.append(n)
    if type_=="dict":
        dic={}
        for a in list_:
            if a in dic:
                dic[a]+=1
            else:
                dic[a]=1
        return dic
    elif type_=="list":
        return list_
    else:
        return None
def floor_(n,x=1):
    return x*(n//x)
def ceil_(n,x=1):
    return x*((n+x-1)//x)
###################################################
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 a in range(M):
        x,y,c=map(int,input().split())
        x-=1
        y-=1
        ans=min(ans,A[x]+A[y]-c)
    print(ans)





main()

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import sys
import heapq
import re
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from fractions import gcd
from math import factorial, sqrt
from functools import lru_cache, reduce
INF = 1 << 60
mod = 1000000007
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

# UnionFind
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

# ダイクストラ
def dijkstra_heap(s, edge, n):
    #始点sから各頂点への最短距離
    d = [10**20] * n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d

# 素因数分解
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

# 2数の最小公倍数
def lcm(x, y):
    return (x * y) // gcd(x, y)

# リストの要素の最小公倍数
def lcm_list(numbers):
    return reduce(lcm, numbers, 1)

# リストの要素の最大公約数
def gcd_list(numbers):
    return reduce(gcd, numbers)

# ここから書き始める
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] + a[y - 1] - c)
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import sys

stdin = sys.stdin

ns = lambda : stdin.readline().rstrip()
ni = lambda : int(ns())
na = lambda : list(map(int, stdin.readline().split()))
sys.setrecursionlimit(10 ** 7)

def main():
    a, b, m = na()
    mina = 1e9+7
    A = []
    for i in range(a):
        A.append(ni())
        mina = min(mina, A[i])
    minb = 1e9+7
    B = []
    for i in range(b):
        B.append(ni())
        minb = min(minb, B[i])

    ans = mina + minb
    for i in range(m):
        x, y, c = na()
        ans = min(ans, A[x] + B[y] - c)
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import sys

stdin = sys.stdin

ns = lambda : stdin.readline().rstrip()
ni = lambda : int(ns())
na = lambda : list(map(int, stdin.readline().split()))
sys.setrecursionlimit(10 ** 7)

def main():
    a, b, m = na()
    mina = 1e9+7
    for i in range(a):
        A.append(ni())
        mina = min(mina, A[i])
    minb = 1e9+7
    for i in range(b):
        B.append(ni())
        minb = min(minb, B[i])

    ans = mina + minb
    for i in range(m):
        x, y, c = na()
        ans = min(ans, A[x] + B[y] - c)
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
a2=input()
a=a.split()
a1=a1.split(" ")
a2=a2.split()
l=[]
for i in a1:
    for j in a2:
     l.append(int(i)+int(j))
for i in range(int(a[2])):
    dis=input()
    dis=dis.split()
    l.append(int(a1[int(dis[0])-1])+int(a2[int(dis[1])-1])-int(dis[2]))
l1=sorted(set(l))
print(l1[0])

Submission status: Runtime Error

Solution code:
a=a.split()
a1=a1.split(" ")
a2=a2.split()
l=[]
for i in a1:
    for j in a2:
     l.append(int(i)+int(j))
for i in range(int(a[2])):
    dis=input()
    dis=dis.split()
    l.append(int(a1[int(dis[0])-1])+int(a2[int(dis[1])-1])-int(dis[2]))
l1=sorted(set(l))
print(l1[0])

Submission status: Runtime Error

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

amin = min(A)
bmin = min(B)
smin = amin + bmin

for i in range(m):
  x, y, c= map(int, input().split())
  th = smin -c
  apmin = A[x]
  if apmin > th:
    pass
  else:
    bpmin = B[y]
    spmin = apmin + bpmin -c
    if spmin < smin:
      smin = spmin
    else:
      pass
print(smin)

Submission status: Runtime Error

Solution code:
_, _, M = map(int, input().split())
# price list
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
# min price
min_price = min(a_list) + min(b_list)
for _ in range(M):
  x, y, c = map(int, input().split())
  discount_price = a_list[x] + b_list[y] - c
  if discount_price < min_price:
    min_price = discount_price
print(min_price)

Submission status: Runtime Error

Solution code:
A, B, M = map(int, input().split())
# price list
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
# min price
min_price = min(a_list) + min(b_list)
for m in range(M):
  x, y, c = map(int, input().split())
  discount_price = a_list[x] + b_list[y] - c
  if discount_price < min_price:
    min_price = discount_price
print(min_price)

Submission status: Runtime Error

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

m=[[0] * B for i in range(A)]

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

minc=min(a)+min(b)

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

  if cash<minc:
    minc=cash


print(minc)

Submission status: Runtime Error

Solution code:
a,b,m=map(int,input().split())
price_A=list(map(int,input().split()))
price_B=list(map(int,input().split()))
coupon=[]
for _ in range(m):
  coupon.append(list(map(int,input().split())))
ans=min(price_A)+min(price_B[0])
for i in range(m):
  deprice=price_A[coupon[i][0]-1]+price_B[coupon[i][1]-1]-coupon[i][2]
  if deprice < ans:
    ans = deprice
print(ans)

Submission status: Runtime Error

Solution code:
def getMinSumPrice(x,y):
    return int(min(x)) + int(min(y))

def getMinCouponPrice(z):
    tmp = []
    for Arr in z:
        if int(Arr[0]) + int(Arr[1]) > int(Arr[2]):
            tmp.append(int(Arr[0]) + int(Arr[1]) - int(Arr[2]))
    return min(tmp)

A = input().split(" ")
a = input().split(" ")
b = input().split(" ")
C = []
for i in range(0, int(A[2])):
  val = input("値を入力").split(" ")
  if val:
    C.append(val)

if getMinSumPrice(a, b) > getMinCouponPrice(C):
    print(getMinCouponPrice(C))
else:
    print(getMinSumPrice(a, b))

Submission status: Runtime Error

Solution code:
numA, numB, numCoupon = map(int, input().split(' '))
priceA = map(int, input().split(' '))
priceB = map(int, input().split(' '))

# initial best price
bestPrice = min(priceA) + min(priceB)

for n in range(numCoupon):
  # get coupon details
  typeA, typeB, discount = map(int, input().split(' '))
  # calculate price when this coupon is used
  currentPrice = priceA[typeA-1] + priceB[typeB-1] - discount
  # update best price
  if currentPrice < bestPrice:
    bestPrice = currentPrice

print(bestPrice)

Submission status: Runtime Error

Solution code:
numA, numB, numCoupon = map(int, input().split(' '))
priceA = map(int, input().split(' '))
priceB = map(int, input().split(' '))

# initial best price
bestPrice = min(priceA) + min(priceB)

for n in range(numCoupon):
  # get coupon details
  typeA, typeB, discount = map(int, coupon.split(' '))
  # calculate price when this coupon is used
  currentPrice = priceA[typeA-1] + priceB[typeB-1] - discount
  # update best price
  if currentPrice < bestPrice:
    bestPrice = currentPrice

print(bestPrice)