[백준] 11399번: ATM

whitehousechef·2023년 9월 15일
0

https://www.acmicpc.net/problem/11399

initial

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)

revisited jan 24th

dafuq so easy btw time complexity is n log n due to sort, not n

another solution

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))

complexity

O(n) time and space complexity

0개의 댓글