[ 알고리즘 ]/Greedy

    [프로그래머스] 두 큐 합 같게 만들기

    [프로그래머스] 두 큐 합 같게 만들기

    📌문제 https://school.programmers.co.kr/learn/courses/30/lessons/118667 🎖️난이도 Level 2 ✔️풀이 from collections import deque def solution(queue1, queue2): # 예외처리 sum1, sum2 = sum(queue1), sum(queue2) total = sum1 + sum2 if total % 2 == 1 or max(queue1) > total/2 or max(queue2) > total/2: return -1 if sum1 == sum2: return 0 total = int(total/2) q1, q2 = deque(queue1), deque(queue2) cnt = 0 # greedy whil..

    [프로그래머스] 단속카메라

    [프로그래머스] 단속카메라

    📌문제 https://school.programmers.co.kr/learn/courses/30/lessons/42884 🎖️난이도 Level 3 ✔️풀이 def solution(routes): routes.sort(key = lambda x : x[1]) # 빠져나간 시간 기준으로 오름차순 정렬 camera = routes[0][1] # 첫번째 차 빠져나간 곳("진출 기준")에 우선 첫번째 카메라 설치하고 시작 cnt = 1 for i in range(1, len(routes)): if routes[i][0] > camera: # 진입 시점이 기존 카메라 위치보다 더 밖(앞)에 있으면 cnt += 1 camera = routes[i][1] # 진출 시점에 새로 설치 return cnt 🧠노트 그리디....

    [프로그래머스] 구명보트

    [프로그래머스] 구명보트

    📌문제 https://school.programmers.co.kr/learn/courses/30/lessons/42885 🎖️난이도 Level 2 ✔️풀이 # sol1) deque, popleft, pop from collections import deque def solution(people, limit): people.sort() # [10, 50, 50, 70, 80, 100] queue = deque(people) cnt = 0 while queue: j = len(queue) - 1 if queue[0] + queue[j]

    [백준] 1946. 신입 사원

    [백준] 1946. 신입 사원

    📌문제 https://www.acmicpc.net/problem/1946 🎖️난이도 ✔️풀이 import sys input = sys.stdin.readline # 안해주면 시간초과 t = int(input()) for _ in range(t): n = int(input()) scores = [] for i in range(n): a, b = map(int, input().split()) scores.append((a, b)) tmp_max = 0 cnt = 0 scores.sort(key = lambda x : x[0]) # 정렬 후 완전 탐색 (tmp_max와 비교) for i in range(n): if i == 0 or scores[i][1] < tmp_max: cnt += 1 tmp_max = ..

    [백준] 21758. 꿀 따기

    [백준] 21758. 꿀 따기

    📌문제 21758번: 꿀 따기 첫 번째 줄에 가능한 최대의 꿀의 양을 출력한다. www.acmicpc.net 🎖️난이도 ✔️풀이 n = int(input()) honey = list(map(int, input().split())) # 누적합 구해놓기 nujuck = [honey[0]] for i in range(1, n): nujuck.append(nujuck[-1]+honey[i]) total = 0 # 1. 통"벌"벌 => [0][1~n-2][-1] for i in range(1, n-1): total = max(total, nujuck[n-2]-honey[i]+nujuck[i-1]) # 2. 벌"벌"통 => [0][1~n-2][-1] for i in range(1, n-1): total = max(..