import sys from collections import deque input = sys.stdin.readline n, k = map(int, input().split()) # n: 플러그 개수 usage = list(map(int, input().split())) plug = usage[:1] # 앞 두개가 모두 같은 숫자일 수 있으므로 1개만 꽂아넣기 usage = deque(usage[1:]) result = 0 while usage: i = usage.popleft() # 이미 꽂혀있을 경우 if i in plug: continue # 플러그 자리가 남았을 경우 if len(plug) < n: plug.append(i) continue # 꽂혀있는 것들 중 뽑을 것 고르기(plug inde..
Greedy
import sys input = sys.stdin.readline # 팀의 수가 최소 # i번은 팀원 수가 자기 자신 포함 xi명 이하여야함 n = int(input()) xi = [0 for _ in range(n+1)] # xi의 범위는 1 O(n) 다른 사람 풀이 - 위 아이디어를 좀 더 간단하게 구현할 수 있다. xi 배열을 인원수 측정에 사용하지 않고 그냥 입력값 그대로 받아서 오름차순으로 정렬한다. 그리고 그냥 최대 인원 수 대로 끊어서 센다(간단 그잡채ㅋㅋㅋㅋ내 고민이 너무 허무해~) N = int(input()) X = list(map(int,input().split())) X.sort() i, cnt = 0, 0 while i < len(X): cnt += 1 i += X[i] prin..
def solution(people, limit): boat = [] people.sort() light = people[0] idx = 0 for i in range(len(people)-1, -1, -1): if idx > i: break person = people[i] if person + light > limit: # 가장 가벼운 사람이랑도 못앉으면 혼자 가야지 boat.append(person) continue # 가장 가벼운 사람이랑은 같이 앉아갈 수 있다! 그럼 앉아가슈 if idx < i: boat.append(person + light) idx += 1 light = people[idx] continue # 앉아갈 짝이 없으면 혼자 가렴 boat.append(person) return ..