結果

問題 No.838 Noelちゃんと星々3
ユーザー AEnAEn
提出日時 2022-05-27 15:44:25
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 358 bytes
コンパイル時間 160 ms
コンパイル使用メモリ 81,848 KB
実行使用メモリ 94,640 KB
最終ジャッジ日時 2023-10-20 19:42:51
合計ジャッジ時間 3,017 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 37 ms
53,576 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 36 ms
53,576 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 36 ms
53,576 KB
testcase_17 AC 36 ms
53,576 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 36 ms
53,576 KB
testcase_21 AC 36 ms
53,576 KB
testcase_22 AC 36 ms
53,576 KB
testcase_23 AC 36 ms
53,576 KB
testcase_24 AC 36 ms
53,576 KB
testcase_25 AC 36 ms
53,576 KB
testcase_26 AC 36 ms
53,576 KB
testcase_27 AC 36 ms
53,576 KB
testcase_28 AC 36 ms
53,576 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
A = list(map(int, input().split()))
A.sort()
res = A[1]-A[0]
B = [A[1], A[1]]
for i in range(2, N):
    if i < N-1:
        if abs(B[-1]-A[i]) < abs(A[i+1]-A[i]):
            B.append(B[-1])
            res += A[i]-B[-1]
        else:
            B.append(A[i+1])
            res += A[i+1]-A[i]
    else:
        res += A[i]-B[-1]
print(res)
0