M, N, L = map(int, input().split()) A = list(map(int, input().split())) B = list(map(int, input().split())) L = [list(map(int, input().split())) for _ inrange(L)]
limits = set() for x, y in L: limits.add((x-1, y-1))
mains = [(val, idx) for idx, val inenumerate(A)] sides = [(val, idx) for idx, val inenumerate(B)]
ans = 0 for i inrange(M): flag = False for j inrange(N): x, y = mains[i][1], sides[j][1] if (x, y) in limits: flag = True continue ans = max(ans, mains[i][0] + sides[j][0]) break ifnot flag: break print(ans)
defsolve() -> int: M, N, L = map(int, input().split()) A = list(map(int, input().split())) B = list(map(int, input().split())) L = [list(map(int, input().split())) for _ inrange(L)]
limits = set() for x, y in L: limits.add((x-1, y-1))
arrA = [(val, idx) for idx, val inenumerate(A)] arrB = [(val, idx) for idx, val inenumerate(B)] arrA.sort(key=lambda x: x[0]) arrB.sort(key=lambda x: x[0])
if (arrA[-1][1], arrB[-1][1]) notin limits: return arrA[-1][0] + arrB[-1][0] ans = 0 for (i, j) in limits: x = bisect_left(arrA, (A[i], i)) # 二分查找 A[i] 在 arrA 中的位置 x y = bisect_left(arrB, (B[j], j)) # 二分查找 B[j] 在 arrB 中的位置 y if x > 0and (arrA[x - 1][1], j) notin limits: # (x - 1, y) 不在限制中 ans = max(ans, arrA[x - 1][0] + B[j]) if y and (i, arrB[y - 1][1]) notin limits: # (x, y - 1) 不在限制中 ans = max(ans, A[i] + arrB[y - 1][0]) return ans
Cover photo is created by @インデックス, thanks for their work!
I did not find any copyright declaration on the author’s personal page regarding permission or prohibition of use. Because of this, I used Pixiv.Cat to proxy the cover image. I actually do not save that image.
If the content of the article infringes on your copyright, please contact me through email or leave a comment to let me know, and I will promptly remove the relevant content.