結果
問題 | No.1120 Strange Teacher |
ユーザー |
|
提出日時 | 2023-03-05 16:57:15 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 89 ms / 1,000 ms |
コード長 | 518 bytes |
コンパイル時間 | 151 ms |
コンパイル使用メモリ | 82,100 KB |
実行使用メモリ | 103,220 KB |
最終ジャッジ日時 | 2024-09-18 01:37:10 |
合計ジャッジ時間 | 4,316 ms |
ジャッジサーバーID (参考情報) |
judge6 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 27 |
ソースコード
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("-1")else:print(abs(a[0] - b[0]))exit()if sa - sb < 0 or (sa - sb) % (n - 2) != 0:print("-1")exit()cnt = (sa - sb) // (n - 2)rest = cntfor i in range(n):a[i] -= cntif a[i] > b[i]:print("-1")exit()else:cost = min(rest, (b[i] - a[i]) // 2)a[i] += 2 * costrest -= costif a == b:print(cnt)else:print("-1")