結果

問題 No.1120 Strange Teacher
ユーザー tamato
提出日時 2020-07-26 20:47:48
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 76 ms / 1,000 ms
コード長 1,025 bytes
コンパイル時間 161 ms
コンパイル使用メモリ 82,560 KB
実行使用メモリ 102,372 KB
最終ジャッジ日時 2024-06-28 19:22:09
合計ジャッジ時間 3,084 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

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

    if N == 2:
        if sum(A) != sum(B):
            print(-1)
        else:
            print(abs(A[0] - B[0]))
        exit()

    if A == B:
        print(0)
        exit()

    SA = sum(A)
    SB = sum(B)
    if SA <= SB:
        print(-1)
    else:
        if (SA - SB) % (N-2):
            print(-1)
        else:
            cnt = 0
            ok = 1
            k = (SA - SB) // (N-2)
            for a, b in zip(A, B):
                if a - k > b:
                    ok = 0
                    break
                else:
                    if (b - (a-k)) % 2 != 0:
                        ok = 0
                        break
                    cnt += (b - (a-k)) // 2
            if ok == 0 or cnt != k:
                print(-1)
            else:
                print(k)


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