diff --git "a/syheo/codingTest1/11-4-\353\247\214\353\223\244 \354\210\230 \354\227\206\353\212\224 \352\270\210\354\225\241.py" "b/syheo/codingTest1/11-4-\353\247\214\353\223\244 \354\210\230 \354\227\206\353\212\224 \352\270\210\354\225\241.py" new file mode 100644 index 0000000..da0c59d --- /dev/null +++ "b/syheo/codingTest1/11-4-\353\247\214\353\223\244 \354\210\230 \354\227\206\353\212\224 \352\270\210\354\225\241.py" @@ -0,0 +1,15 @@ +#CH11 그리디 기출 +#예제 11-4 +#만들 수 없는 금액 + +N = int(input()) +coins = list(map(int,input().split())) +answer = 1 +coins.sort() +for i in range(N): + if coins[i]<=answer: + answer+=coins[i] + else: + print(answer) + + diff --git "a/syheo/codingTest1/11-5-\353\263\274\353\247\201\352\263\265 \352\263\240\353\245\264\352\270\260.py" "b/syheo/codingTest1/11-5-\353\263\274\353\247\201\352\263\265 \352\263\240\353\245\264\352\270\260.py" new file mode 100644 index 0000000..c8f9ece --- /dev/null +++ "b/syheo/codingTest1/11-5-\353\263\274\353\247\201\352\263\265 \352\263\240\353\245\264\352\270\260.py" @@ -0,0 +1,28 @@ +#CH11 그리디 기출 +#예제 11-5 +#볼링공 고르기 + +#N은 볼링공 갯수, M은 공의 최대 무게 +N , M = map(int,input().split()) + +balls = list(map(int,input().split())) +balls.sort() +sum = 0 +postSum = 0 +curSum = 0 +cur = 0 +#현재 공 무게와 다른 이전 공의 갯수 * 현재 공 무게의 갯수를 sum에 더해나감 +for ball in balls: + if ball!=cur: + cur = ball + sum+=curSum*postSum + postSum+=curSum + curSum=1 + else: + curSum+=1 +sum+=curSum*postSum +print(sum) + + + + diff --git "a/syheo/codingTest1/11-6-\353\254\264\354\247\200\354\235\230 \353\250\271\353\260\251 \353\235\274\354\235\264\353\270\214.py" "b/syheo/codingTest1/11-6-\353\254\264\354\247\200\354\235\230 \353\250\271\353\260\251 \353\235\274\354\235\264\353\270\214.py" new file mode 100644 index 0000000..74ac7ca --- /dev/null +++ "b/syheo/codingTest1/11-6-\353\254\264\354\247\200\354\235\230 \353\250\271\353\260\251 \353\235\274\354\235\264\353\270\214.py" @@ -0,0 +1,41 @@ +#CH11 그리디 기출 +#예제 11-6 +#무지의 먹방 라이브 +#카카오 신입 공채 2019 + +#엄청 오래 걸림 +#효율성 있게 하기 어려웠음. +import heapq +from collections import deque + +def solution(food_times, k): + answer = 0 + rest = k # 남은 시간 + length = len(food_times) + #k 시간 안에 현재 음식을 다먹을 수 있을 경우 + if sum(food_times)<=k: + return -1 + + q = [] + #(식사시간, 음식 위치)를 우선순위 큐에 넣어줌 O(logN)xN + for i in range(length): + heapq.heappush(q,(food_times[i],i)) + + rotation = q[0][0] # 진행할 로테이션 횟수 + prev_rot = 0 + #큐에 음식이 있고, 로테이션 진행 가능시 + while rest>=len(q)*(rotation-prev_rot): + #남은 횟수 + rest-=(rotation-prev_rot)*len(q) + #rotation만큼 돌릴 수 있는 음식 제거 + while q[0][0]==rotation: + heapq.heappop(q) + #로테이션 갱신 + prev_rot = rotation + rotation = q[0][0] + + #음식 번호로 정렬 O(NlogN) + q.sort(key=lambda x : x[1]) + answer = q[rest%len(q)][1]+1 + + return answer \ No newline at end of file