Submission #18887518


Source Code Expand

N = int(input())
A = list(map(int, input().split()))
A.sort()
arr = [0] * (N + 1)
for i in reversed(range(N)):
    arr[i] = arr[i + 1] + A[i]

ans = 0
for i in range(N-1):
    ans += arr[i+1] - A[i] * (N-i-1)
print(ans)

Submission Info

Submission Time
Task D - Sum of difference
User noyan
Language PyPy3 (7.3.0)
Score 400
Code Size 229 Byte
Status AC
Exec Time 137 ms
Memory 94336 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 2
AC × 25
Set Name Test Cases
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
Case Name Status Exec Time Memory
hand_01.txt AC 66 ms 61672 KiB
max_01.txt AC 123 ms 94336 KiB
max_02.txt AC 105 ms 94140 KiB
random_01.txt AC 134 ms 93756 KiB
random_02.txt AC 133 ms 94024 KiB
random_03.txt AC 132 ms 94032 KiB
random_04.txt AC 134 ms 94008 KiB
random_05.txt AC 137 ms 93900 KiB
random_06.txt AC 134 ms 94200 KiB
random_07.txt AC 133 ms 94032 KiB
random_08.txt AC 134 ms 93812 KiB
random_09.txt AC 136 ms 94292 KiB
random_10.txt AC 135 ms 94136 KiB
random_11.txt AC 132 ms 94200 KiB
random_12.txt AC 137 ms 94028 KiB
random_13.txt AC 131 ms 94036 KiB
random_14.txt AC 136 ms 93796 KiB
random_15.txt AC 134 ms 94284 KiB
random_16.txt AC 134 ms 94032 KiB
random_17.txt AC 134 ms 94216 KiB
random_18.txt AC 132 ms 94216 KiB
random_19.txt AC 134 ms 93916 KiB
random_20.txt AC 136 ms 94200 KiB
sample_01.txt AC 52 ms 61676 KiB
sample_02.txt AC 51 ms 61428 KiB