공부-코딩테스트/코테풀이 - 자바, 파이썬
1859. 백만 장자 프로젝트 (코딩테스트, SW Expert Academy)
령과
2022. 5. 10. 16:18
문제
https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV5LrsUaDxcDFAXc
SW Expert Academy
SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!
swexpertacademy.com
나의 코드 : 13분 52초
T = int(input())
for test_case in range(1, T+1):
answer = 0
N = int(input())
input_list = list(map(int, input().split()))
while len(input_list)!=0:
cut_idx = input_list.index(max(input_list))
input_list_before, input_list_after = input_list[:cut_idx+1],input_list[cut_idx+1:]
answer += sum([input_list_before[-1]-i for i in input_list_before])
input_list = input_list_after
print("#"+str(test_case),answer)
가장 큰 수를 찾아 앞부분까지 자른 다음 가장 큰 수와의 차이를 answer에 더한다.
가장 큰 수를 기준으로 자르면 두개의 리스트가 생기고 가장 큰 수가 before에 있다면 after는 다음 타겟 리스트로
이러한 행위를 반복하면 된다.
알게 된 점
a = [1, 2, 3]
a[3]을 하면 오류가 발생한다. 접근 가능한 인덱스 범위에 넘어갔기 때문이다
반대로 a[3:]이런식으로 접근하면 오류는 발생하지 않는다.
D3중에 정답률 낮은 문제 하나 골라서 풀어보다가 10개 중 1개를 통과하지 못하고 1시간 동안 삽질하다
포기하고 다른 공부를 하기위해 마무리 문제겸 이 문제를 해결하였다.
난 아직 한참 멀었다.....