結果

問題 No.3268 As Seen in Toasters
コンテスト
ユーザー LyricalMaestro
提出日時 2025-12-11 01:05:47
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 812 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 395 ms
コンパイル使用メモリ 82,352 KB
実行使用メモリ 118,700 KB
最終ジャッジ日時 2025-12-11 01:05:55
合計ジャッジ時間 7,692 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 31 RE * 10
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

## https://yukicoder.me/problems/no/3268


def main():
    N = int(input())
    A = list(map(int, input().split()))

    a_positive = []
    a_negative = []
    for a in A:
        if a >= 0:
            a_positive.append(a)
        else:
            a_negative.append(a)
    
    a_negative.sort()
    a_positive.sort()

    answer = 0
    for i in range(1, len(a_negative)):
        answer += - a_negative[i - 1] - a_negative[i]
    p = a_negative[-1]
    for a in a_positive:
        answer += a - p
        p = a
    answer1 = answer

    answer2 = float("inf")
    if len(a_negative) >= 2:
        answer += a_negative[0] + a_negative[1]
        answer += -a_negative[0] + a_positive[-1]
        answer2 = answer
    answer = min(answer1, answer2)
    print(answer)




if __name__ == '__main__':
    main()
0