結果

問題 No.1120 Strange Teacher
ユーザー AEnAEn
提出日時 2022-05-21 12:16:30
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 100 ms / 1,000 ms
コード長 520 bytes
コンパイル時間 216 ms
コンパイル使用メモリ 82,540 KB
実行使用メモリ 103,936 KB
最終ジャッジ日時 2024-09-20 11:27:45
合計ジャッジ時間 3,471 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
m = []
for i in range(N):
    m.append(A[i]-B[i])
if N == 2:
    if sum(A) != sum(B):
        print(-1)
    else:
        print(abs(A[0]-B[0]))
    exit()
sm = sum(m)
if sm % (N-2) != 0:
    print(-1)
    exit()
res = sm//(N-2)
for i in range(N):
    m[i] -= res
cnt = 0
for i in range(N):
    if m[i]%2!=0 or m[i]>0:
        print(-1)
        exit()
    cnt += -m[i]//2
    if cnt > res:
        print(-1)
        exit()
print(res)
0