提出 #27708018


ソースコード 拡げる

N = int(input())
A = list(map(int, input().split()))
A.sort()  # 昇順に sort(O(NlogN))

# 累積和の計算
cusum = [0]
for a in A:
    cusum.append(cusum[-1]+a)

ans = 0
for i, a in enumerate(A): # i番目の要素: a
    ans += a*i            # i回 プラス
    ans -= cusum[i]       # 自分より小さい要素の累積和を引く
print(ans)

提出情報

提出日時
問題 D - Sum of difference
ユーザ nasuo
言語 PyPy3 (7.3.0)
得点 400
コード長 370 Byte
結果 AC
実行時間 137 ms
メモリ 108876 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 400 / 400
結果
AC × 2
AC × 25
セット名 テストケース
Sample sample_01.txt, sample_02.txt
All hand_01.txt, max_01.txt, max_02.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, sample_01.txt, sample_02.txt
ケース名 結果 実行時間 メモリ
hand_01.txt AC 73 ms 61616 KiB
max_01.txt AC 124 ms 108876 KiB
max_02.txt AC 100 ms 105364 KiB
random_01.txt AC 133 ms 107124 KiB
random_02.txt AC 134 ms 106960 KiB
random_03.txt AC 135 ms 107012 KiB
random_04.txt AC 133 ms 107244 KiB
random_05.txt AC 134 ms 107308 KiB
random_06.txt AC 131 ms 107276 KiB
random_07.txt AC 131 ms 107212 KiB
random_08.txt AC 129 ms 107316 KiB
random_09.txt AC 130 ms 106796 KiB
random_10.txt AC 130 ms 107012 KiB
random_11.txt AC 134 ms 107276 KiB
random_12.txt AC 134 ms 107148 KiB
random_13.txt AC 132 ms 107072 KiB
random_14.txt AC 136 ms 107008 KiB
random_15.txt AC 137 ms 107252 KiB
random_16.txt AC 135 ms 107196 KiB
random_17.txt AC 132 ms 107196 KiB
random_18.txt AC 135 ms 107216 KiB
random_19.txt AC 134 ms 107212 KiB
random_20.txt AC 135 ms 107076 KiB
sample_01.txt AC 50 ms 61616 KiB
sample_02.txt AC 49 ms 61616 KiB