結果

問題 No.1120 Strange Teacher
ユーザー tamatotamato
提出日時 2020-07-26 20:47:48
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 121 ms / 1,000 ms
コード長 1,025 bytes
コンパイル時間 533 ms
コンパイル使用メモリ 87,488 KB
実行使用メモリ 100,212 KB
最終ジャッジ日時 2023-09-11 04:57:54
合計ジャッジ時間 5,470 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,420 KB
testcase_01 AC 74 ms
71,352 KB
testcase_02 AC 78 ms
76,136 KB
testcase_03 AC 82 ms
76,608 KB
testcase_04 AC 117 ms
99,932 KB
testcase_05 AC 121 ms
99,916 KB
testcase_06 AC 119 ms
100,212 KB
testcase_07 AC 119 ms
99,996 KB
testcase_08 AC 118 ms
100,148 KB
testcase_09 AC 74 ms
71,820 KB
testcase_10 AC 114 ms
100,028 KB
testcase_11 AC 114 ms
100,008 KB
testcase_12 AC 114 ms
99,972 KB
testcase_13 AC 114 ms
99,904 KB
testcase_14 AC 113 ms
100,176 KB
testcase_15 AC 114 ms
100,016 KB
testcase_16 AC 114 ms
100,028 KB
testcase_17 AC 114 ms
99,920 KB
testcase_18 AC 72 ms
71,328 KB
testcase_19 AC 115 ms
98,272 KB
testcase_20 AC 73 ms
71,792 KB
testcase_21 AC 75 ms
71,552 KB
testcase_22 AC 73 ms
71,820 KB
testcase_23 AC 73 ms
71,572 KB
testcase_24 AC 113 ms
99,644 KB
testcase_25 AC 73 ms
71,792 KB
testcase_26 AC 72 ms
71,584 KB
testcase_27 AC 72 ms
71,672 KB
testcase_28 AC 75 ms
71,680 KB
testcase_29 AC 73 ms
71,552 KB
権限があれば一括ダウンロードができます

ソースコード

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