結果

問題 No.1104 オンライン点呼
ユーザー gew1fw
提出日時 2025-06-12 18:01:02
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,069 bytes
コンパイル時間 185 ms
コンパイル使用メモリ 82,344 KB
実行使用メモリ 103,068 KB
最終ジャッジ日時 2025-06-12 18:01:07
合計ジャッジ時間 3,032 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 24 WA * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

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

if N == 1:
    print(0)
else:
    max_time = 0
    # Handle j=2
    time_j2 = A[0] + B[1]
    max_time = time_j2
    if N == 2:
        print(max_time)
        exit()
    
    prev_prev = 0  # time for j-2=1
    prev = time_j2  # time for j-1=2
    max_time = max(max_time, prev)
    
    for j in range(3, N + 1):
        # j is current employee (1-based)
        # j-2 is the index in A for employee j-2 (0-based)
        a_j_minus_1 = A[j-2]  # A[j-2] corresponds to employee j-1's A_i
        b_j = B[j-1]         # B[j-1] is employee j's B_i
        
        condition1 = prev + a_j_minus_1 + b_j
        
        a_j_minus_2 = A[j-3] if j-3 >= 0 else 0  # j >=3 implies j-3 >=0 when j starts from 3
        condition2 = prev_prev + a_j_minus_2 + b_j + K
        
        current = min(condition1, condition2)
        max_time = max(max_time, current)
        
        # Update previous values
        prev_prev, prev = prev, current
    
    print(max_time)
0