結果

問題 No.1120 Strange Teacher
ユーザー qibqib
提出日時 2023-03-05 16:57:15
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 91 ms / 1,000 ms
コード長 518 bytes
コンパイル時間 1,297 ms
コンパイル使用メモリ 81,668 KB
実行使用メモリ 102,696 KB
最終ジャッジ日時 2023-10-18 04:56:24
合計ジャッジ時間 5,544 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,448 KB
testcase_01 AC 38 ms
53,448 KB
testcase_02 AC 42 ms
59,492 KB
testcase_03 AC 47 ms
66,232 KB
testcase_04 AC 90 ms
102,696 KB
testcase_05 AC 90 ms
102,696 KB
testcase_06 AC 89 ms
102,648 KB
testcase_07 AC 90 ms
102,696 KB
testcase_08 AC 90 ms
102,696 KB
testcase_09 AC 39 ms
53,448 KB
testcase_10 AC 81 ms
101,408 KB
testcase_11 AC 81 ms
101,408 KB
testcase_12 AC 81 ms
101,412 KB
testcase_13 AC 81 ms
101,272 KB
testcase_14 AC 80 ms
101,272 KB
testcase_15 AC 80 ms
101,272 KB
testcase_16 AC 82 ms
101,280 KB
testcase_17 AC 81 ms
101,308 KB
testcase_18 AC 38 ms
53,448 KB
testcase_19 AC 91 ms
100,304 KB
testcase_20 AC 38 ms
53,448 KB
testcase_21 AC 38 ms
53,448 KB
testcase_22 AC 38 ms
53,448 KB
testcase_23 AC 38 ms
53,448 KB
testcase_24 AC 88 ms
102,548 KB
testcase_25 AC 38 ms
53,448 KB
testcase_26 AC 37 ms
53,448 KB
testcase_27 AC 37 ms
53,448 KB
testcase_28 AC 38 ms
53,448 KB
testcase_29 AC 38 ms
53,448 KB
権限があれば一括ダウンロードができます

ソースコード

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("-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 = cnt
for i in range(n):
  a[i] -= cnt
  if a[i] > b[i]:
    print("-1")
    exit()
  else:
    cost = min(rest, (b[i] - a[i]) // 2)
    a[i] += 2 * cost
    rest -= cost

if a == b:
  print(cnt)
else:
  print("-1")
0