-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathD.py
40 lines (36 loc) · 810 Bytes
/
D.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import bisect
n = int(input())
a = list(map(int, input().split()))
a.sort()
total = sum(a)
ans = 0
for o, i in enumerate(a, 1):
total -= i
ans += abs(i*(n-o)-total)
print(ans)
# total = sum(a)
# div = [total]
# a = [[i, idx] for idx, i in enumerate(a)]
# new_a = sorted(a, key=lambda x: x[0])
# su = 0
# for i, j in new_a:
# su += i
# div.append(total-su)
# print(total)
# print(new_a)
# print(div)
# ans = 0
# new_a = sorted(new_a, key=lambda x: x[1], reverse=True)
# off = 0
# for i, j in new_a:
# l = j-1
# r = j
# # l = bisect.bisect_left(new_a, i)
# # r = bisect.bisect_right(new_a, i)
# # print(l, r)
# #print()
# ans += l*i-(total-div[l]) + div[r]-off-(n-l)*i
# off += div[l]
# #print(div[bisect.bisect_left(new_a, i)])
# #print()
# print(ans)