結果
問題 | No.1120 Strange Teacher |
ユーザー |
![]() |
提出日時 | 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 |
ソースコード
mod = 1000000007eps = 10**-9def main():import sysinput = sys.stdin.readlineN = 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 = 0ok = 1k = (SA - SB) // (N-2)for a, b in zip(A, B):if a - k > b:ok = 0breakelse:if (b - (a-k)) % 2 != 0:ok = 0breakcnt += (b - (a-k)) // 2if ok == 0 or cnt != k:print(-1)else:print(k)if __name__ == '__main__':main()