https://www.acmicpc.net/problem/11399
very simple, we just sort the list and add the values together
my correct code:
n=int(input())
lst = list(map(int,input().split()))
lst.sort()
ans = 0
prev=0
for i in lst:
prev +=i
ans += prev
print(ans)
dafuq so easy btw time complexity is n log n due to sort, not n
I searched google and some peeps did like this
n = int(input()) # 사람 수
arr = list(map(int,input().split())) # 인출 시간
arr.sort() # 정렬
result = 0
for i in range(1,n):
arr[i] += arr[i-1] # 인출 시간 갱신
print(sum(arr))
O(n) time and space complexity