結果

問題 No.1990 Candy Boxes
ユーザー gew1fw
提出日時 2025-06-12 14:55:54
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 918 bytes
コンパイル時間 306 ms
コンパイル使用メモリ 82,464 KB
実行使用メモリ 106,088 KB
最終ジャッジ日時 2025-06-12 14:58:08
合計ジャッジ時間 6,943 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 53 WA * 18
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
    import sys
    input = sys.stdin.read().split()
    idx = 0
    N = int(input[idx])
    idx += 1
    B = list(map(int, input[idx:idx+N]))
    idx += N
    
    if N == 1:
        # This case is not possible as per problem constraints (N >=2)
        print("Yes")
        return
    
    # Compute the sum S
    S = B[0]
    for i in range(1, N-1):
        if i % 2 == 1:
            S -= B[i]
        else:
            S += B[i]
    if S != B[-1]:
        print("No")
        return
    
    # Compute x_i's and check non-negative
    x = [0] * (N-1)
    x[0] = B[0]
    if x[0] < 0:
        print("No")
        return
    for i in range(1, N-1):
        x[i] = B[i] - x[i-1]
        if x[i] < 0:
            print("No")
            return
    
    # Check if the last x equals B[-1]
    if x[-1] != B[-1]:
        print("No")
        return
    
    print("Yes")

if __name__ == "__main__":
    main()
0