結果

問題 No.1990 Candy Boxes
ユーザー gew1fw
提出日時 2025-06-12 19:57:55
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 807 bytes
コンパイル時間 219 ms
コンパイル使用メモリ 82,376 KB
実行使用メモリ 116,888 KB
最終ジャッジ日時 2025-06-12 20:00:44
合計ジャッジ時間 8,420 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 53 WA * 18
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
    import sys
    input = sys.stdin.read().split()
    N = int(input[0])
    B = list(map(int, input[1:N+1]))
    
    if N == 1:
        print("Yes")
        return
    
    # Compute the alternating 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
    x = []
    x.append(B[0])
    for i in range(1, N-1):
        next_x = B[i] - x[i-1]
        x.append(next_x)
    
    # Check if x[-1] == B[-1]
    if x[-1] != B[-1]:
        print("No")
        return
    
    # Check all x are non-negative
    for num in x:
        if num < 0:
            print("No")
            return
    
    print("Yes")

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