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: Time Limit Exceeded

Solution code:
S = input().split()

#冷蔵庫
A = int(S[0])
#電子レンジ
B = int(S[1])
#割引券
M = int(S[2])



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

total_mini = 999999999
for j in range(A):
    for k in range(B):
        total = a[j] + b[k]
        if total_mini > total:
            total_mini = total



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

    if minimum > amount:
        minimum = amount


if minimum <= total_mini:
    print(minimum)
else:
    print(total_mini)

Submission status: Time Limit Exceeded

Solution code:
listA=[] #appendのために宣言が必要
while True:
    try:
        listA.append(list(map(int,input().split())))

    except:
        break;
        
money = listA[1][0] + listA[2][0]

for i in range(listA[0][0]):
    for j in range(listA[0][1]):
        if listA[1][i] + listA[2][j] < money:
            money = listA[1][i] + listA[2][j] 

for k in range(listA[0][2]):
    a = listA[k+3][0]
    b = listA[k+3][1]
    wari = listA[1][a-1] + listA[2][b-1] - listA[k+3][2]
    if wari < money:
        money = wari
        
        
print(money)

Submission status: Time Limit Exceeded

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

MIN = a[0] + b[0]

for i in range(A):
    for j in range(B):
        
        for k in data:
            if k[0]-1 == i and k[1]-1 == j:
                MIN = min(a[i]+b[j]-k[2], MIN)

        MIN = min(a[i]+b[j], MIN) 

print(MIN)

Submission status: Time Limit Exceeded

Solution code:
# input
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
x, y, c = [0] * M, [0] * M, [0] * M
for i in range(M):
    x[i], y[i], c[i] = map(int, input().split())
ans = float("inf")

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

for i in range(A):
    for j in range(B):
        ans = min(ans, a[i] + b[j])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# input
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
x, y, c = [0] * M, [0] * M, [0] * M
for i in range(M):
    x[i], y[i], c[i] = map(int, input().split())
ans = float("inf")
for i in range(A):
    for j in range(B):
        cmax = 0
        for k in range(M):
            if i+1 == x[k] and j+1 == y[k]:
                cmax = max(cmax, c[k])
        res = a[i] + b[j] - cmax
        ans = min(ans, res)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main():
  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 = {}
  for i in range(M):
    x,y,c = [int(i) for i in input().split()]
    t = "%s,%s" % (x-1 ,y-1)
    if t in C:
      if C[t] < c:
        C[t] = c
    else:
    	C[t] = c
  r = 100000;
  for i in range(A):
    for j in range(B):
      z = a[i] + b[j]
      t = "%s,%s" % (i,j)
      if t in C:
        z = z - C[t]
      if z < r:
        r = z
  print(r)

if __name__ == "__main__":
  main()

Submission status: Time Limit Exceeded

Solution code:
list_num = input().split(" ") #A,B,M
list_ref = input().split(" ") #冷蔵庫の値段
list_ren = input().split(" ") #レンジの値段
list2 = [] #割引できるやつの組み
for i in range(int(list_num[2])):
    list_c = input().split(" ")
    list2.append(list_c)
A = int(list_num[0])
B = int(list_num[1])
M = int(list_num[2])
 
#割引なしで総当たり
list_price = []
for i in range(A):
    for j in range(B):
        list_price.append(int(list_ref[i]) + int(list_ren[j]))
 
#割引きを総当たり
for k in range(M):
    price = int(list_ref[int(list2[k][0])-1]) + int(list_ren[int(list2[k][1])-1]) - int(int(list2[k][2])-1) - 1
    list_price.append(price)
 
 
print(min(list_price))

Submission status: Time Limit Exceeded

Solution code:
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 10**9 + 10

for i in range(A):
    for j in range(B):
        num = a[i] + b[j]
        if num < ans:
            ans = num

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

print(ans)

Submission status: Time Limit Exceeded

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=99999999999
for i in range(a):
    for j in range(i,b):
        ans=min(ans,A[i]+B[j])
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: Time Limit Exceeded

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=99999999999
for i in A:
    for j in B:
        ans=min(ans,i+j)
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: Time Limit Exceeded

Solution code:
import sys
import numpy as np

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

prices_A=np.array(list(map(int,input().split())),dtype='int32')
prices_B=np.array(list(map(int,input().split())),dtype='int32')

dc_index=dict()
dc=np.zeros((1,B),dtype='int32')

k=0
for n in range(M):
    (x,y,c)=map(int,input().split())
    i=x-1
    j=y-1
    if i not in dc_index:
        dc_index[i]=k
        # prepare for next one
        dc=np.concatenate([dc, np.zeros((1,B),dtype='int32')],axis=0)
        k+=1
    if c > dc[dc_index[i],j]:
        dc[dc_index[i],j]=c

#print(prices_A)
#print(prices_B)
#print(dc)
#print(dc_index)

min_p = prices_A[0] + prices_B[0]
for i in range(A):
    if i in dc_index:
        price_B_dc=prices_B-dc[dc_index[i]]
        p=prices_A[i]+price_B_dc.min()
    else:
        p=prices_A[i]+prices_B.min()
        
    if p < min_p:
        min_p=p
print(min_p)

Submission status: Time Limit Exceeded

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

def main():
    A,B,M = list(map(int, input().split(' ')))

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

    dic = {}
    for i in range(A):
        dic[i]={}
    for i in range(A):
        for j in range(B):
            dic[i][j] = 0


    price_list = 2*10**5
    for i in range(M):
        temp = list(map(int, input().split(' ')))
        if price_list > a_list[temp[0]-1] + b_list[temp[1]-1] - temp[2]:
            price_list = a_list[temp[0]-1] + b_list[temp[1]-1] - temp[2]

    lower = min(a_list) + min(b_list)
    if lower < price_list:
        print(lower)
    else:
        print(price_list)

if __name__=='__main__':
    main()

Submission status: Time Limit Exceeded

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

def main():
    A,B,M = list(map(int, input().split(' ')))

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

    dic = {}
    for i in range(A):
        dic[i]={}
    for i in range(A):
        for j in range(B):
            dic[i][j] = 0


    x_y_c_list = []

    for i in range(M):
        temp = list(map(int, input().split(' ')))
        x_y_c_list.append(temp)

        if dic[temp[0]-1][temp[1]-1] == 0:
            dic[temp[0]-1][temp[1]-1] = temp[2]
        else:
            if dic[temp[0]-1][temp[1]-1] < temp[2]:
                dic[temp[0]-1][temp[1]-1] = temp[2]

    price_list = -1
    for i in range(A):
        for j in range(B):
            if price_list == -1:
                price_list = a_list[i]+b_list[j] - dic[i][j]
            elif price_list > a_list[i]+b_list[j] - dic[i][j]:
                price_list = a_list[i]+b_list[j] - dic[i][j]
            else:
                price_list = price_list
            #price_list.append(a_list[i]+b_list[j] - dic[i][j])

    print(price_list)

if __name__=='__main__':
    main()

Submission status: Time Limit Exceeded

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

def main():
    A,B,M = list(map(int, input().split(' ')))

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

    dic = {}
    for i in range(A):
        dic[i]={}
    for i in range(A):
        for j in range(B):
            dic[i][j] = 0


    x_y_c_list = []

    for i in range(M):
        temp = list(map(int, input().split(' ')))
        x_y_c_list.append(temp)

        if dic[temp[0]-1][temp[1]-1] == 0:
            dic[temp[0]-1][temp[1]-1] = temp[2]
        else:
            if dic[temp[0]-1][temp[1]-1] < temp[2]:
                dic[temp[0]-1][temp[1]-1] = temp[2]

    price_list = []
    for i in range(A):
        for j in range(B):
            price_list.append(a_list[i]+b_list[j] - dic[i][j])

    print(min(price_list))

if __name__=='__main__':
    main()

Submission status: Time Limit Exceeded

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

def main():
    A,B,M = list(map(int, input().split(' ')))

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

    x_y_c_list = []

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

    price_list = []
    for i in range(A):
        for j in range(B):
            for k in x_y_c_list:
                if k[:2] == [i+1, j+1]:
                    price_list.append(a_list[i]+b_list[j] - k[2])
                price_list.append(a_list[i]+b_list[j])

    print(min(price_list))

if __name__=='__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

num = 100000

for _ in range(M):
    m1,m2,m3 = map(int,input().split())
    for q in range(A):
        for w in range(B):
            res = int(a[q])+int(b[w])
            if q+1 == m1 and w+1 == m2: res-=m3
            num = min(num,res)
print(num)

Submission status: Time Limit Exceeded

Solution code:
import sys

def disscount(disscounts,x,y):
  minDisscounts = 0
  for i in disscounts:
    if int(i[0]) == x and int(i[1]) == y:
      if minDisscounts < int(i[2]):
        minDisscounts = int(i[2])
  return minDisscounts

counts = input().split()
colors = input().split()
hots = input().split()
disscounts = []
for i in range(int(counts[2])):
  disscounts.append(input().split())

minPrice = sys.maxsize
for i in range(0, len(colors)):
  for j in range(0, len(hots)):
    colorPrice = int(colors[i])
    hotPrice = int(hots[j])
    price = colorPrice + hotPrice - disscount(disscounts, i + 1 , j + 1)
    if price < minPrice:
      minPrice = price
print(str(minPrice))

Submission status: Time Limit Exceeded

Solution code:
a,b,m=map(int,input().split())
ai=list(map(int, input().split()))
bi=list(map(int, input().split()))
sm=[list(map(int, input().split())) for _ in range(m)]
ans=10**6
for i in range(a):
    for j in range(b):
        for x in range(m):
            k=ai[i]+bi[j]
            if sm[x][0]==i+1 and sm[x][1]==j+1:
                k=k-sm[x][2]
            if ans >=k:
                ans=k
print(ans)

Submission status: Time Limit Exceeded

Solution code:
a,b,m=map(int, input().split())
fridge=list(map(int, input().split()))
microwave=list(map(int, input().split()))
s=[list(map(int,list(input().split()))) for i in range(m)]
discount = [[0 for i in range(b)] for j in range(a)]


def mapDiscountByXY(m,discount,s):
  for i in range(m):
    if discount[s[i][0]-1][s[i][1]-1] < s[i][2]:
      discount[s[i][0]-1][s[i][1]-1] = s[i][2]
  return discount


def findMin(a,b,fridge,microwave,discount):
  lowest = 100000
  
  for i in range(a):
    for j in range(b):
      if lowest > fridge[i]+microwave[j]-discount[i][j]:
        lowest = fridge[i]+microwave[j]-discount[i][j]
  return lowest


discount = mapDiscountByXY(m,discount,s)
print(findMin(a,b,fridge,microwave,discount))

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

from sys import stdin

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

    return ab_price


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

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

    return ab_price

def generate_table(a_list, b_list,  pricedown_list):
    ab_price = [[[] for i in range(len(b_list))] for j in range(len(a_list))]
    max_price_down = 0
    min_a = min(a_list)
    min_b = min(b_list)
    min_price = min_a + min_b

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



    return min_price


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

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

#a_list = list(map(int, input().split()))
a_list = [int(x) for x in stdin.readline().rstrip().split()]
b_list = [int(x) for x in stdin.readline().rstrip().split()]

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


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

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

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

min_price = generate_table(a_list, b_list,  pricedown_list)

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

print(min_price)

Submission status: Time Limit Exceeded

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

from sys import stdin

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

    return ab_price


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

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

    return ab_price

def generate_table(a_list, b_list,  pricedown_list):
    ab_price = [[[] for i in range(len(b_list))] for j in range(len(a_list))]
    max_price_down = 0
    min_price = float('inf')
    for i, a_price in enumerate(a_list):
        for j, b_price in enumerate(b_list):
            ab_price[i][j] = a_price + b_price

            """値引きを考える"""
            for k, l, price in pricedown_list:
                if (i,j) == (k-1, l-1):
                    max_price_down = max(max_price_down, price)

            ab_price[i][j] -= max_price_down
            min_price = min(min_price, ab_price[i][j])

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

        ab_price[i-1][j-1] -= price
    """
    return min_price


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

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

#a_list = list(map(int, input().split()))
a_list = [int(x) for x in stdin.readline().rstrip().split()]
b_list = [int(x) for x in stdin.readline().rstrip().split()]

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


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

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

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

min_price = generate_table(a_list, b_list,  pricedown_list)

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

print(min_price)

Submission status: Time Limit Exceeded

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

from sys import stdin

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

    return ab_price


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

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

    return ab_price

def generate_table(a_list, b_list,  pricedown_list):
    ab_price = [[[] for i in range(len(b_list))] for j in range(len(a_list))]
    max_price_down = 0
    for i, a_price in enumerate(a_list):
        for j, b_price in enumerate(b_list):
            ab_price[i][j] = a_price + b_price

            """値引きを考える"""
            for k, l, price in pricedown_list:
                if (i,j) == (k-1, l-1):
                    max_price_down = max(max_price_down, price)

            ab_price[i][j] -= max_price_down

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

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


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

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

#a_list = list(map(int, input().split()))
a_list = [int(x) for x in stdin.readline().rstrip().split()]
b_list = [int(x) for x in stdin.readline().rstrip().split()]

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


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

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

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

price_table = generate_table(a_list, b_list,  pricedown_list)

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

print(min_price)

Submission status: Time Limit Exceeded

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

from sys import stdin

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

    return ab_price


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

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

    return ab_price

def generate_table(a_list, b_list,  pricedown_list):
    ab_price = [[a_list[j]+b_list[i] for i in range(len(b_list))] for j in range(len(a_list))]
    """値段表から値引きする"""
    for i, j , price in pricedown_list:
        for k, l, price2 in pricedown_list:
            if (i, j) == (k, l) and price >= price2:
                continue
            elif (i, j) == (k, l) and price < price2:
                price = 0

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

    return ab_price


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

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

#a_list = list(map(int, input().split()))
a_list = [int(x) for x in stdin.readline().rstrip().split()]
b_list = [int(x) for x in stdin.readline().rstrip().split()]

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


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

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

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

price_table = generate_table(a_list, b_list,  pricedown_list)

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

print(min_price)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

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

C=[[] for i in range(len(A))]

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

ans=10**9
for ia,a in enumerate(A):
    temp=B[:]
    for index,money in C[ia]:
        #print(index,money)
        temp[index]=min(B[index]-money,temp[index])
    temp.sort()
    ans=min(ans,a+temp[0])

print(ans)

Submission status: Time Limit Exceeded

Solution code:
A,B,M = map(int,input().split())
al = list(map(int,input().split()))
bl = list(map(int,input().split()))
lis = [list(map(int,input().split())) for k in range(M)]
risuto = []
for a in range(len(al)):
  for b in range(len(bl)):
    for l in lis:
      allm = al[a] + bl[b]
      #print(l)
      if a+1 == l[0] and b+1 == l[1]:
        allm -= l[2]
      risuto.append(allm)
#print(risuto)
print(min(risuto))

Submission status: Time Limit Exceeded

Solution code:
A,B,M = map(int,input().split())
al = list(map(int,input().split()))
bl = list(map(int,input().split()))
lis = [list(map(int,input().split())) for k in range(M)]
risuto = []
for a in range(len(al)):
  for b in range(len(bl)):
    for l in lis:
      allm = al[a] + bl[b]
      #print(l)
      if a+1 == l[0] and b+1 == l[1]:
        allm -= l[2]
        risuto.append(allm)
      else:
        risuto.append(allm)
#print(risuto)
print(min(risuto))

Submission status: Time Limit Exceeded

Solution code:
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
xyc = list(list(map(int, input().split())) for _ in range(M))
l1 = []
lx = []
ly = []
min_a = min(a)
min_b = min(b)

for k in range(M):
    lx.append(list(x for x, y, c in xyc))
    ly.append(list(y for x, y, c in xyc))
    l1.append(list(c for x, y, c in xyc))
    j = lx[0][k]
    p = ly[0][k]
    max_l1 = max(list(map(int, max(l1))))
    ans = min((min_a + min_b), ((a[j - 1] + b[p - 1]) - max_l1))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
abm = input('')
a = int(abm.split(' ')[0])
b = int(abm.split(' ')[1])
m = int(abm.split(' ')[2])
wdic = {}
pdic = {}
clist = input('').split(' ')
dlist = input('').split(' ')

# 冷蔵庫と電子レンジ価格辞書の作成
cddic = {}
for i in range(0,a):
  for j in range(0,b):
    key = str(i+1) + "-" + str(j+1)
    cddic[key] = int(clist[i]) + int(dlist[j])


# 割引辞書の作成
for i in range(0,m):
  win = input('').split(' ')
  wc = win[0]
  wd = win[1]
  wkey = wc + "-" + wd # 割引キー
  wp = int(win[2]) # 割引価格  
  if wkey in wdic.keys():
    if wp > wdic[wkey]:
      cddic[wkey] = cddic[wkey] + wdic[wkey] - wp
      wdic[wkey] = wp
  else:
    cddic[wkey] = cddic[wkey] - wp
    wdic[wkey] = wp

min_price = min(cddic.values())
#max_w = max(wdic.values())
print(min_price)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

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

ans = []

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

a = set(a)
b = set(b)
temp = list(itertools.product(a, b))
for i,j in temp:
    ans.append(i+j)

print(min(ans))

Submission status: Time Limit Exceeded

Solution code:
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
xyc = list(list(map(int, input().split())) for _ in range(M))
l1 = []
lx = []
ly = []
for i in range(M):
    l1.append(list(c for x, y, c in xyc))
min_a = min(a)
min_b = min(b)
max_l1 = max(list(map(int, max(l1))))
for k in range(M):
    lx.append(list(x for x, y, c in xyc))
    ly.append(list(y for x, y, c in xyc))
    j = lx[0][k]
    p = ly[0][k]
    ans = min((min_a + min_b), ((a[j - 1] + b[p - 1]) - max_l1))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
import numpy as np

def main():
    fridge_count, microwave_count, coupon_count = map(int, input().split(' '))
    fridges = np.array(list(map(int, input().split(' '))))
    microwaves = np.array(list(map(int, input().split(' '))))
    coupons = []
    for _ in range(coupon_count):
        coupons.append(list(map(int, input().split(' '))))
    # print(fridges, microwaves, coupons)

    prices = set()
    for coupon in coupons:
        prices.add(fridges[coupon[0]-1] + microwaves[coupon[1]-1] - coupon[2])
    for fridge in set(sorted(fridges)):
        for microwave in set(sorted(microwaves)):
            if (fridge + microwave) < min(prices):
                prices.add(fridge + microwave)
            else:
                break
    # print(prices)

    print(min(prices))

    return 0


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
xyc = list(list(map(int, input().split())) for _ in range(M))
l1 = []
lx = []
ly = []
for i in range(100001):
    l1.append(list(c for x, y, c in xyc))
min_a = min(a)
min_b = min(b)
max_l1 = max(list(map(int, max(l1))))
for k in range(M):
    lx.append(list(x for x, y, c in xyc))
    ly.append(list(y for x, y, c in xyc))
    j = lx[0][k]
    p = ly[0][k]
    ans = min((min_a + min_b), ((a[j - 1] + b[p - 1]) - max_l1))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

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

ans = []

for i in range(M):
    x[i], y[i], c[i] = [int(k) for k in input().split()]

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

a = set(a)
b = set(b)
temp = list(itertools.product(a, b))
for i,j in temp:
    ans.append(i+j)

print(min(ans))

Submission status: Time Limit Exceeded

Solution code:
abm = input('')
a = int(abm.split(' ')[0])
b = int(abm.split(' ')[1])
m = int(abm.split(' ')[2])
wdic = {}
pdic = {}
clist = input('').split(' ')
dlist = input('').split(' ')

# 冷蔵庫と電子レンジ価格辞書の作成
cddic = {}
for i in range(0,a):
  for j in range(0,b):
    key = str(i+1) + "-" + str(j+1)
    cddic[key] = int(clist[i]) + int(dlist[j])

cddic = sorted(cddic.items(), key=lambda x:x[1])

# 割引辞書の作成
for i in range(0,m):
  win = input('').split(' ')
  wc = win[0]
  wd = win[1]
  wkey = wc + "-" + wd # 割引キー
  wp = int(win[2]) # 割引価格  
  if wkey in wdic.keys():
    if wp > wdic[wkey]:
      wdic[wkey] = wp
  else:
    wdic[wkey] = wp

max_w = max(wdic.values())

# 価格表組み合わせの作成
min_price = -1
for cd in cddic:
    key = str(cd[0])
    val = int(cd[1])
    w = 0
    if key in wdic.keys():
      w = wdic[key]
    # 商品金額の合計が最大割引額を考えてもオーバーする場合、終了
    price = val - w
    if min_price == -1:
      min_price = price
    elif price < min_price:
      min_price = price
    pdic[key] = price
    if (val - max_w) > min_price:
      break

# 割引後価格でソート
#pdic2 = sorted(pdic.items(), key=lambda x:x[1])
# ソート結果の1件目の値が最安値
# print(pdic2)
print(min_price)