結果

問題 No.1120 Strange Teacher
ユーザー arahi10arahi10
提出日時 2020-07-24 23:33:46
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 169 ms / 1,000 ms
コード長 471 bytes
コンパイル時間 87 ms
コンパイル使用メモリ 10,892 KB
実行使用メモリ 23,888 KB
最終ジャッジ日時 2023-09-08 05:34:41
合計ジャッジ時間 3,845 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,756 KB
testcase_01 AC 16 ms
7,800 KB
testcase_02 AC 16 ms
8,224 KB
testcase_03 AC 31 ms
9,588 KB
testcase_04 AC 169 ms
23,592 KB
testcase_05 AC 166 ms
23,668 KB
testcase_06 AC 167 ms
23,512 KB
testcase_07 AC 166 ms
23,676 KB
testcase_08 AC 165 ms
23,596 KB
testcase_09 AC 16 ms
7,812 KB
testcase_10 AC 74 ms
23,816 KB
testcase_11 AC 75 ms
23,780 KB
testcase_12 AC 74 ms
23,628 KB
testcase_13 AC 72 ms
23,592 KB
testcase_14 AC 72 ms
23,580 KB
testcase_15 AC 72 ms
23,596 KB
testcase_16 AC 73 ms
23,680 KB
testcase_17 AC 72 ms
23,536 KB
testcase_18 AC 16 ms
7,852 KB
testcase_19 AC 152 ms
23,888 KB
testcase_20 AC 16 ms
7,768 KB
testcase_21 AC 15 ms
7,808 KB
testcase_22 AC 16 ms
8,240 KB
testcase_23 AC 16 ms
7,812 KB
testcase_24 AC 157 ms
20,732 KB
testcase_25 AC 15 ms
7,936 KB
testcase_26 AC 15 ms
8,108 KB
testcase_27 AC 15 ms
7,760 KB
testcase_28 AC 15 ms
7,824 KB
testcase_29 AC 16 ms
8,220 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n=int(input())
a,b=[list(map(int,input().split())) for i in range(2)]
if n==2:
    if sum(a)==sum(b):
        print(sum(A-B for A,B in zip(a,b)if A>B))
    else:print(-1)
else:
    v=sum(a)-sum(b)
    if v<0 or v%(n-2):print(-1)
    else:
        k=v//(n-2)
        f=k
        for x,y in zip(a,b):
            if (x-y-k)%2 or k+min(x-y,y-x)<0:print(-1);exit()
            bc=(y-x+k)//2
            if f<bc:print(-1);exit()
            f-=bc
        print(-1 if f else k)
0