結果

問題 No.1120 Strange Teacher
ユーザー LyricalMaestro
提出日時 2024-08-10 00:10:42
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 802 bytes
コンパイル時間 459 ms
コンパイル使用メモリ 82,372 KB
実行使用メモリ 103,652 KB
最終ジャッジ日時 2024-08-10 00:10:47
合計ジャッジ時間 4,220 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 22 WA * 5
権限があれば一括ダウンロードができます

ソースコード

diff #

## https://yukicoder.me/problems/no/1120

def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))

    sum_b = sum(B)
    sum_a = sum(A)

    if N == 2:
        if sum_a == sum_b:
            return abs(A[0] - B[0])
        else:
            return -1
    else:
        diff = sum_a - sum_b
        if diff % (N - 2) != 0:
            print(-1)
            return
    
        n = diff // (N - 2)
        sum_n = 0
        for i in range(N):
            d = A[i] - B[i]
            x = n - d
            if x % 2 != 0:
                print(-1)
                return
            sum_n += x // 2

        if sum_n != n:
            print(-1)
            return
        else:
            print(n)












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