목록Algorithm/Ch 2. 기초 알고리즘 (5)
토니의 연습장
https://www.acmicpc.net/problem/11399 두 가지 주요사항:1. 무엇을 선택할지 : 각 순서에 누구를 배치할지2. 어떤 순서로 선택할지 : 앞 또는 뒤에서부터 누구를 배치할지 -> 뒤에서부터 배치N = int(input())P = list(map(int, input().split()))P = sorted(P)total = 0for i in range(N): total += sum(P[:i+1]) print(total) https://www.acmicpc.net/problem/2847 두 가지 주요사항:1. 무엇을 선택할지 : 각 레벨의 보상을 몇으로 할지2. 어떤 순서로 선택할지 : 높은 레벨부터 보상 값을 결정하는 방향 N = int(input())L = [0]*..
https://www.acmicpc.net/problem/2003 N, M = map(int,input().split())A = list(map(int, input().split()))# 1. 합 = M : 시작점을 +1start = 0end = 0sum = A[0]count = 0while True: # 현재 구간 합이 M인지 확인 if sum == M: count += 1 # 구간 업데이트 if sum >= M: start += 1 sum -= A[start-1] else: if end == N-1: # 끝점 +1 하려는데 구간 종료될 상황이라면 break end += 1 ..
https://www.acmicpc.net/problem/2309from itertools import combinationsheights = []for _ in range(9): height = int(input()) heights.append(height) for a in combinations(heights, 7): if sum(a) == 100: a = list(a) # tuple은 sort 불가하여 list로 먼저 변환 a.sort() for x in a: print(x) break https://www.acmicpc.net/problem/10819 from itertools import permutati..
https://www.acmicpc.net/problem/1946 import sysinput = sys.stdin.readline # 입력 빠르게 받기 위한 세팅T = int(input())for _ in range(T): N = int(input()) candidates = [] for _ in range(N): s, m = map(int, input().split()) candidates.append((s,m)) # (s,m) candidates.sort() # 첫 번째 인자 기준 먼저 정렬, 같을 경우 두 번째 인자 기준 정렬됨 # but 문제 조건상 동석차 없음 top_ranking = 1e9 # 현재까지..
https://www.acmicpc.net/problem/2512 찾고자 하는 값 : 최적의 상한액탐색 범위 : [ 0, 지방 요청 금액 중 최댓값 ]시뮬레이션 : [ 0, 150 ] -> [ 75, 150 ] -> ...N = int(input())jibang = list(map(int, input().split()))budget = int(input())left = 0right = max(jibang)answer = -1while left https://www.acmicpc.net/problem/2343 # 탐색하려는 값 : 블루레이의 용량# 탐색 볌위 : [ 영상길이의 최댓값, 영상길이의 합 ]N, M = map(int, input().split())running_time = list(map(i..