Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- DRF
- Prefetch_related
- QuerySet
- Coroutine
- 코루틴
- Python
- EC2
- apitestcase
- Git
- F객체
- aws
- CD
- nestedfunction
- DjangoRestFramework
- DjangoCache
- aggregate
- to_attr
- Transaction
- testcase
- database
- dry-yasg
- Continuous Delivery
- docker
- annotate
- 백준
- django
- Continuous Deployment
- 도커
- CI
- racecondition
Archives
- Today
- Total
BackEnd King KY
백준 11399 본문
728x90
✔️ 문제
https://www.acmicpc.net/problem/11399
11399번: ATM
첫째 줄에 사람의 수 N(1 ≤ N ≤ 1,000)이 주어진다. 둘째 줄에는 각 사람이 돈을 인출하는데 걸리는 시간 Pi가 주어진다. (1 ≤ Pi ≤ 1,000)
www.acmicpc.net
✔️ 풀이
n = int(input())
l = list(map(int, input().split()))
l.sort()
tot = 0
for i in range(len(l)):
tot += sum(l[:i+1])
print(tot)
오름차순으로 정렬한 다음 이전의 합들의 합(?)을 구해야 하는 문제여서 피보나치 개념으로 풀 수 있지 않을까 싶었습니다.
그래서 f(n-1)+f(n-2) 이렇게 하려고 했는데 그건 너무 코드가 쓸 데 없이 작성될 것? 같아서 슬라이싱 개념으로 하는 게 어떨까 생각이 들었습니다.
✔️ 다른 사람 풀이
n = int(input())
a=t=0
for i in sorted(list(map(int, input().split()))):
a += i
t += a
print(t)
input으로 받은 값을 변수 선언 따로 하지 않고 for문에 넣어서 값들의 합인 a와 총합인 t를 함께 구하는 풀이가 있었습니다.