프로그래머스
from collections import deque
def solution(bridge_length, weight, truck_weights):
answer = 0
que = deque()
n = len(truck_weights)
truck_weights = deque(truck_weights)
t = 0
trucks = 0
while truck_weights:
if len(que)>0:
w, time = que[0]
if time == t:
que.popleft()
trucks -= w
if bridge_length > len(que) and weight >= trucks+truck_weights[0]:
temp = truck_weights.popleft()
que.append((temp, t+bridge_length))
trucks += temp
t += 1
answer = t+bridge_length
return answer
def solution(citations):
citations.sort(reverse=True)
n = len(citations)
answer = 0
for i in range(n):
if citations[i] <= i:
answer = i
break
return answer
def solution(n, times):
answer = 0
left = 1
right = n * max(times)
while left < right:
mid = (left + right) // 2
temp = 0
for time in times:
temp += mid // time
if temp >= n:
right = mid
else:
left = mid+1
answer = left
return answer
def solution(numbers):
numbers = list(map(str, numbers))
numbers.sort(reverse=True, key=lambda x:x*5)
answer = str(int(''.join(numbers)))
return answer
import heapq
def solution(operations):
answer = [0,0]
min_heap = []
max_heap = []
for op in operations:
num = int(op[2:])
if op[0]=="I":
heapq.heappush(min_heap, num)
heapq.heappush(max_heap, -num)
else:
if len(min_heap) > 0:
if num == 1:
max_num = heapq.heappop(max_heap)
min_heap.remove(-max_num)
else:
min_num = heapq.heappop(min_heap)
max_heap.remove(-min_num)
if len(min_heap) != 0:
answer = [-max_heap[0], min_heap[0]]
return answer