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:
import sys

def load(vtype=int):
    return vtype(input().strip())


def load_list(seplator=" ", vtype=int):
    return [vtype(v) for v in input().strip().split(seplator)]

A, B, M = tuple(load_list())

a = load_list()
b = load_list()

coupon = dict()
for _ in range(M):
    x, y, c = tuple(load_list())
    if (x-1, y-1) in coupon:
        coupon[(x-1,y-1)] = max(coupon[(x-1,y-1)], c)
    else:        
        coupon[(x-1, y-1)] = c 

minv = min(a) + min(b)

for key, value in coupon.items():
    i, j = key
    minv = min(minv, a[i] + b[i] - value)

print(minv)

Submission status: Runtime Error

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()]
c=[[0]*a for i in range(b)]
for i in range(m):
    x,y,z=[int(i)for i in input().split()]
    c[x-1][y-1]=z

mx=A[0]+B[0]-c[0][0]
for i in range(a):
    for j in range(b):
        if mx > A[i]+B[j]-c[j][i]:
            mx = A[i]+B[j]-c[j][i]
#print(A)
#print(B)
#rint(c)
print(mx)

Submission status: Runtime Error

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

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

ans = 9999999999
for i in range(A):
    for j in range(B):
        price = a[i] + b[j] - m[i][j]
        if price < ans:
            ans = price
print(ans)

Submission status: Runtime Error

Solution code:
import sys

def main():
    input = sys.stdin.readline

    _, _, m = input().split()
    m = int(m)
    alist = input().split()
    blist = input().split()

    waribiki = [input().split() for _ in range(m)]
    
    res = [None] * (len(alist)*len(blist) + m)
    count = 0
    for a in alist:
      for b in blist:
        res[count] = int(a)+int(b)
        count += 1

    for i in range(m):
        res[count] = int(alist[int(waribiki[i][0])-1]) + int(blist[int(waribiki[i][1])-1]) - int(waribiki[i][2])
        count += 1
      
    print(min(res))


if __name__ == '__main__':
    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()))
ans = []

waribiki = [[0] * A for i in range(B)]
for _ in range(M):
    x,y,c = map(int,input().split())
    waribiki[x-1][y-1]=c

for numA,i in enumerate(a):
    for numB,j in enumerate(b):
        ans.append(i+j-waribiki[numB][numA])

print(min(ans))

Submission status: Runtime Error

Solution code:
a, b, m = map(int, input().split())
A = [map(int, input().split())]
B = [map(int, input().split())]
C = sorted(A)
D = sorted(B)
l = C[0] + D[0]

for i in range(m):
  x, y, c = map(int, input().split())
  k = A[x-1] + B[y-1] -c
  if l > k:
    l = k
  else:
    l = l
print(l)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
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())))
m = np.zeros((A, B), dtype="int64")

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

ans = 9999999999
for i in range(A):
    for j in range(B):
        price = a[i] + b[j] - m[i][j]
        if price < ans:
            ans = price
print(ans)

Submission status: Runtime Error

Solution code:
AC, BC, MC = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
M = [tuple(map(int, input().split())) for _ in range(MC)]

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

Submission status: Runtime Error

Solution code:
import math
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
minA = math.inf
minB = math.inf
for reizou in a:
    if reizou < minA:
        minA = reizou
for renzi in b:
    if renzi < minB:
        minB = renzi
min = minA + minB
for i in range(M):
    x,y,c = map(int,input().split())
    sum = a[x-1] + b[y-1] - c
    if sum < min:
        min = sum

print(sum)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

pa = [int(p) for p in input().split()]
pb = [int(p) for p in input().split()]

pc = []
for c in range(m):
  x, y, d = list(map(int, input().split()))
  pc.append(pa[x-1]+pa[y-1]-d)
  
min_c = min(pc)
min_ab = min(pa)+min(pb)

if min_c < min_ab:
  print(min_c)
else:
  print(min_ab)

Submission status: Runtime Error

Solution code:
A, B, C = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
mi = 10**6
for i in range(M):
  x, y, c = map(int, input().split())
  tmp = A[x-1] + B[y-1] - c
  if mi > tmp:
    mi = tmp
A.sort()
B.sort()
tmp = A[0] + B[0]
if mi > tmp:
  mi = tmp
print(mi)

Submission status: Runtime Error

Solution code:
2 2 1
3 5
3 5
2 2 2

Submission status: Runtime Error

Solution code:
import sys

input = sys.stdin.readline


def main():
    a, b, m = map(int, input().split())
    refrigerators = list(map(int, input().split()))
    microwaves = list(map(int, input().split()))
    tickets = [list(map(int, input().split())) for _ in range(m)]
    tickets_map = {}
    for x, y, c in tickets:
        key = f'{x - 1}:{y - 1}'
        tickets_map[key] = c

    ret = 99999999999999
    for x in range(a):
        for y in range(b):
            key = f'{x}:{y}'
            d = tickets_map.get(key, 0)
            p = refrigerators[x] + microwaves[y] - d
            ret = min(ret, p)
    print(ret)


if __name__ == '__main__':
    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()))

min_cost = min(a) + min(b)

for i in range(M):
  x = list(map(int,input().split()))
  cost = a[x[0]] + b[x[1]] - x[2]

  if min_cost > cost:
    min_cost = cost

print(min_cost)

Submission status: Runtime Error

Solution code:
import sys

def load(vtype=int):
    return vtype(input().strip())


def load_list(seplator=" ", vtype=int):
    return [vtype(v) for v in input().strip().split(seplator)]

A, B, M = tuple(load_list())

a = load_list()
b = load_list()

coupon = dict()
for _ in range(M):
    x, y, c = tuple(load_list())
    if (x, y) in coupon:
        coupon[(x-1,y-1)] = max(coupon[(x,y)], c)
    else:        
        coupon[(x-1, y-1)] = c 

minv = min(a) + min(b)

for key, value in coupon.items():
    i, j = key
    minv = min(minv, a[i] + b[i] - value)

print(minv)

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

Submission status: Runtime Error

Solution code:
import sys
input=sys.stdin.readline

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

ans = min(a)+min(b)
for i1,i2,discount in x:
    sum = a[i1-1]+a[i2-1]-discount
    ans = min(ans,sum)

print(ans)

Submission status: Runtime Error

Solution code:
import sys

def load(vtype=int):
    return vtype(input().strip())


def load_list(seplator=" ", vtype=int):
    return [vtype(v) for v in input().strip().split(seplator)]

A, B, M = tuple(load_list())

a = load_list()
b = load_list()

coupon = dict()
for _ in range(M):
    x, y, c = tuple(load_list())
    if (x, y) in coupon:
        coupon[(x,y)] = min(coupon[(x,y)], c)
    else:        
        coupon[(x-1, y-1)] = c 

minv = min(a) + min(b)

for key, value in coupon.items():
    i, j = key
    minv = min(minv, a[i] + b[i] - value)
print(minv)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
a, b, m = map(int, input().split())
A = [map(int, input().split())]
B = [map(int, input().split())]
C = sorted(A)
D = sorted(B)
l = C[0] + D[0]

for i in range(m):
  x, y, c = map(int, input().split())
  k = A[x-1] + B[y-1] -c
  if l > k:
    l = k
  else:
    continue
print(l)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
AC, BC, MC = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

M = [[0 for _ in range(AC)] for __ in range(BC)]
for i in range(MC):
    x, y, c = map(int, input().split())
    M[x-1][y-1] = max(M[x-1][y-1], c)

ans = 10**8
for a in range(AC):
    for b in range(BC):
        ans = min(ans, A[a-1] + B[b-1] - M[a-1][b-1])
print(ans)

Submission status: Runtime Error

Solution code:
a, b, m = map(int, input().split())
arr = list(map(int, input().split()))
brr = list(map(int, input().split()))
crr = [[0] * b for _ in range(a)]
xycs = [tuple(map(int, input().split())) for _ in range(m)]
ans = min(arr) + min(brr)

for elem in xycs:
    x = elem[0]
    y = elem[1]
    c = elem[2]
    ans = min(arr[x - 1] + arr[y - 1] - c, ans)

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()))
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[A[i][0]-1]+B[lst[i][1]-1]-lst[i][2]
  if v>V:
    v=V
print(v)

Submission status: Runtime Error

Solution code:
a,b,m=map(int,input().split())
alis=list(map(int,input().split()))
blis=list(map(int,input().split()))
ans=10**18
d=dict()
for i in range(m):
  x,y,c=map(int,input().split())
  x-=1
  y-=1
  d[(x,y)]=c
  ans=min(ans,alis[x]+blis[y]-c)
alis1=[]
blis1=[]
for i in range(a):
  alis1.append((alis[i],i))
for i in range(a):
  blis1.append((blis[i],i))
alis1.sort()
blis1.sort()
if (alis1[0][1],blis1[0][1]) not in d:
  ans=min(ans,alis1[0][0]+blis1[0][0])
print(ans)

Submission status: Runtime Error

Solution code:
// #pragma GCC optimize "trapv" Uncomment when dealing with huge numbers
/*<----------PBDS---------->

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
template <typename T>
using order_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

order_set<datatype>oset;
Kth smallest : *oset.find_by_order(k-1); // 0 based index
No of elements less than k : oset.order_of_key(k);
Erase X : oset.erase(x)
<----------PBDS---------->*/
#include<iostream>
#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
#define pb(x) push_back(x)
#define gcd(a,b) __gcd(a,b)
#define all(v) v.begin(),v.end()
#define lcm(a,b) (a*b)/gcd(a,b)
#define bits(x) __builtin_popcountll(x)
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int32_t main()
{
	int p,q,m;
	cin >> p >> q >> m;
	int a[p],b[q];
	int a1=INT_MAX;
	int b1=INT_MAX;
	for(int i = 0 ; i< p ;i++ ){
		cin >> a[i];
		a1 = min(a[i],a1);
	}
	for(int j = 0 ; j <q ; j++ ){
		cin >> b[j];
		b1 = min(b[j],b1);
	}
	int ans = INT_MAX;
	for(int i = 0 ; i < m ; i++ ){
		int x,y,z;
		cin >> x >> y >> z;
		x--;
		y--;
		ans = min({ans,a[x]+b[y]-z,a1+b1});
	}
	cout<<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()))
xyc = [tuple(map(int, input().split())) for _ in range(M)]

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

Submission status: Runtime Error

Solution code:
A, B, M = [int(num) for num in input().split()]
a = [int(num) for num in input().split()]
b =  [int(num) for num in input().split()]
minimum = -1
for i in range(M):
    xi, yi, ci =  [int(num) for num in input().split()]
    ai = a[xi]
    bi = b[yi]
    sum = ai + bi - ci
    if minimum == -1 or sum < minimum:
        minimum = sum
print(minimum)

Submission status: Runtime Error

Solution code:
#B
#入力
A,B,M=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
d=[list(map(int,input().split())) for i in range(M)]

#処理
x=min(a)+min(b)

for i in d:
    t=a[d[0]-1]+b[d[1]-1]-d[2]
    if t>x:
        x=t
print(x)

Submission status: Runtime Error

Solution code:
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time


def I(): return int(input())


def S(): return input()


def MI(): return map(int, input().split())


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def print_matrix(mat):
    for i in range(len(mat)):
        print(*mat)


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YNL = {False: 'No', True: 'Yes'}
YNU = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']

show_flg = False
# show_flg = True


def main():
    A, B, M = MI()
    a = LI()
    b = LI()
    x = [0] * M
    y = [0] * M
    c = [0] * M
    ans = 10**9
    # min_x_i = 10**9
    # min_y_i = 10**9
    # min_x = 10**9
    # min_y = 10**9

    for i in range(M):
        x[i], y[i], c[i] = MI()

    for i in range(M):
        A = a[x[i]-1]
        B = a[y[i]-1]
        ans = min(ans, A + B - c[i])
        # if min_x > x[i]:
        #     min_x = x[i]
        #     min_x_i = i

        # if min_y > y[i]:
        #     min_y = y[i]
        #     min_y_i = i

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

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

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

print(ans)

Submission status: Runtime Error

Solution code:
def main():
    _, _, m_num = map(int, input().split())
    a = [int(s) for s in input().split()]
    b = [int(s) for s in input().split()]

    min_price = min(a) + min(b)

    m = []
    for _ in range(m_num):
        price = a[x - 1] + b[y - 1] - c
        print(x, y, c, price)
        min_price = min(min_price, price)
    
    print(min_price)

main()

Submission status: Runtime Error

Solution code:
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

A, B, M = LI()
a = LI()
b = LI()
xyc = [[] for i in range(M)]
for i in range(M):
    x, y, c = LI()
    x -= 1
    y -= 1
    xyc[i] = [x, y, c]

ans = mod
for i in range(M):
    x, y, c = xyc[i]
    ans = min(ans, a[x] + a[y] - c)

ans = min(ans, min(a) + min(b))
print(ans)

Submission status: Runtime Error

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()]
mina, minb = min(a), min(b)
minv = mina+minb
for _ in range(M):
    x, y, c = [int(i) for i in input().split()]
    x -= 1
    y -= 1
    minv = min(minv, a[x]+a[y]-c)


print(minv)

Submission status: Runtime Error

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()))
a_idx = a.index(min(a))
b_idx = b.index(min(b))
#print(a_idx,b_idx)

ans = min(a)+min(b)
for i in range(m):
    x,y,c = map(int,input().split())
    if x-1 != a_idx or y-1 != b_idx:
        ans = min(ans,a[x-1]+b[x-1]-c)
    if x-1 == a_idx and y-1 == b_idx:
        ans = min(ans,a[x-1]+b[x-1]-c)
print(ans)

Submission status: Runtime Error

Solution code:
s=list(map(int,input().split()))
t=list(map(int,input().split()))
u=list(map(int,input().split()))
v=[list(map(int,input().split())) for i in range(s[2])]
a=10**6
d=0
e=0
for i in range(s[2]):
  d=v[i][0]-1
  e=v[i][0]-1
  b=t[d]+u[e]-v[i][2]
  a=min(a,b)
print(a)

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 = [0] * M
y = [0] * M
c = [0] * M
for i in range(M):
    x[i], y[i], c[i] = map(int, input().split())

min_cost = min(a) + min(b)

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

print(min_cost)

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

amin = min(a)
bmin = min(b)

ans = amin + bmin

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

print(ans)

Submission status: Runtime Error

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()]
mina, minb = min(a), min(b)
minv = 10000000000
for _ in range(M):
    x, y, c = [int(i) for i in input().split()]
    x -= 1
    y -= 1
    minv = min(minv, a[x]+a[y]-c)


print(min(minv, mina+minb))

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

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

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

print(ans)

Submission status: Runtime Error

Solution code:
def main():
    a_n, b_n, m = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    ans = 10**8
    for _ in range(m):
        x, y, c = map(int, input().split())
        x -= 1
        y -= 1
        buf = a[x] + b[x] - c
        if buf < ans:
            ans = buf
    a.sort()
    b.sort()
    if a[0] + b[0] < ans:
        ans = a[0] + b[0]
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

ans = min(a)+min(b)
for i1,i2,discount in x:
    sum = a[i1-1]+a[i2-1]-discount
    ans = min(ans,sum)

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

mn = min(A) + min(B)

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

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

ans = min(a) + min(b)
for i, (xi, yi, ci) in enumerate(xyc):
    ans = min(ans, a[xi - 1] + a[yi - 1] - ci)

print(ans)

Submission status: Runtime Error

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

def ri():
    return int(input())

def rl():
    return list(input().split())

def rli():
    return list(map(int, input().split()))

def main():
    a, b, m = rli()
    la = rli()
    lb = rli()
    ans = min(la)+min(lb)
    for i in range(m):
        x, y, c = rli()
        x -= 1
        y -= 1
        ans = min(ans, la[x]+lb[x]-c)
    print(ans)


if __name__ == '__main__':
    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()))
ans=1162513825187421
for _ in range(m):
    i,j,c=map(int,input().split())
    ans=min(ans, A[i-1]+B[i-1]-c)
print(ans)

Submission status: Runtime Error

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

ref = list(map(int,input().split()))
mic = list(map(int,input().split()))

ans = min(ref)+min(mic)


for i in range(m):
    x,y,c = map(int,input().split())
    x-=1
    y-=1

    if ref[x]+ref[y]-c < ans:
        ans = ref[x]+ref[y]-c

print(ans)

Submission status: Runtime Error

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

ans = min(a)+min(b)

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

print(ans)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

a,b,m = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
a = min(A); b=min(B)
mans = a+b
for _ in range(m):
  x,y,c = map(int,input().split())
  x-=1;b-=1
  tmp = A[x] + B[x] - c
  mans = min(mans,tmp)
print(mans)

Submission status: Runtime Error

Solution code:
import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__


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

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