結果

問題 No.1120 Strange Teacher
ユーザー H20
提出日時 2021-08-24 11:24:59
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 86 ms / 1,000 ms
コード長 504 bytes
コンパイル時間 161 ms
コンパイル使用メモリ 82,460 KB
実行使用メモリ 103,536 KB
最終ジャッジ日時 2024-11-14 03:57:05
合計ジャッジ時間 3,250 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
SA = sum(A)
SB = sum(B)
if N==2:
    if SA==SB:
        print(abs(B[0]-A[0]))
    else:
        print(-1)
    exit()


if (SA-SB)%(N-2)==0:
    cnt = (SA-SB)//(N-2)
    temp = 0
    for i in range(N):
        if B[i]-(A[i]-cnt)<0 or (B[i]-(A[i]-cnt))%2==1:
            print(-1)
            exit()
        temp += B[i]-(A[i]-cnt)
    if temp//2==cnt:
        print(cnt)
    else:
        print(-1)
else:
    print(-1)
0