結果
| 問題 | No.949 飲酒プログラミングコンテスト |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-12-09 01:29:56 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 1,939 ms / 2,500 ms |
| コード長 | 1,967 bytes |
| 記録 | |
| コンパイル時間 | 388 ms |
| コンパイル使用メモリ | 82,412 KB |
| 実行使用メモリ | 148,560 KB |
| 最終ジャッジ日時 | 2025-12-09 01:30:21 |
| 合計ジャッジ時間 | 23,114 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 29 |
ソースコード
## https://yukicoder.me/problems/no/944
from collections import deque
MAX_INT = 10 ** 18
def bisearch(N, D, f, low_index):
if low_index == N:
return N
if D[-1] > f:
return N
low = low_index
high = N - 1
while high - low > 1:
mid = (high + low) //2
if D[mid] <= f:
high = mid
else:
low = mid
if D[low] <= f:
return low
else:
return high
def main():
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
D = list(map(int, input().split()))
D.sort(reverse=True)
queue = deque()
queue.append((0, 0))
min_d_index = [[MAX_INT for _ in range(N + 1)] for _ in range(N + 1)]
min_d_index[0][0] = -1
for n in range(N + 1):
for a_index in range(0, n + 1):
b_index = n - a_index
if min_d_index[a_index][b_index] == MAX_INT:
continue
d_index = min_d_index[a_index][b_index]
if d_index == N - 1:
continue
# a_index + 1する
new_a_index = a_index + 1
new_b_index = b_index
f = A[new_a_index] + B[new_b_index]
eat_index = bisearch(N, D, f, d_index + 1)
if eat_index < N:
min_d_index[new_a_index][new_b_index] = min(min_d_index[new_a_index][new_b_index], eat_index)
new_a_index = a_index
new_b_index = b_index + 1
f = A[new_a_index] + B[new_b_index]
eat_index = bisearch(N, D, f, d_index + 1)
if eat_index < N:
min_d_index[new_a_index][new_b_index] = min(min_d_index[new_a_index][new_b_index], eat_index)
answer = 0
for a in range(N + 1):
for b in range(N + 1):
if min_d_index[a][b] < MAX_INT:
answer = max(answer, a + b)
print(answer)
if __name__ == "__main__":
main()