Notice
Recent Posts
Recent Comments
- Today
- Total
01-11 01:45
Tags
- tree
- array
- MST
- ๋ฐฑ์๋
- PS
- BFS
- dp
- ์๋ฐ
- pytorch
- OOP
- ์กธ์ ์ํ
- ๋ฐฑ์ค
- leetcode
- ๊ตฌํ
- Graph
- ์๋ฃ๊ตฌ์กฐ
- ๋ฌธ๋ฒ
- CS
- java
- ์๋ฐ์์ ์
- ๊ทธ๋ฆฌ๋
- ๋ฐ์ดํฐ๋ฒ ์ด์ค
- spring
- database
- ์์์ ๋ ฌ
- ๋ฒจ๋งํฌ๋
- ํ๋ก๊ทธ๋๋จธ์ค
- ์ธํด
- ๋ค์ต์คํธ๋ผ
- Algorithm
Link
Partially Committed
[ํ๋ก๊ทธ๋๋จธ์ค] ๋ ๋งต๊ฒ ๋ณธ๋ฌธ
728x90
๋ฐ์ํ
SMALL
https://school.programmers.co.kr/learn/courses/30/lessons/42626#
์ค์ฝ๋น ์ง์๊ฐ ๊ธฐ๋ก๋ scoville ๋ฐฐ์ด์์ K ๋ณด๋ค ์์ scoville ์ ๊ฐ์ง ์์๊ฐ ์๋ค๋ฉด ์ต์ scoville ์, ๊ทธ ๋ค์์ผ๋ก ํฐ scoville ์ ์ด์ฉํ์ฌ ์๋ก์ด ์์๋ฅผ ์ถ๊ฐํ๋ค. ์ด๋ฅผ ์ํด์ ์ต์ํ์ ์ฌ์ฉํ๋ค.
#include <string>
#include <vector>
#include <queue>
#include <functional>
#include <iostream>
#define ll long long
using namespace std;
int solution(vector<int> scoville, int K) {
priority_queue <int, vector<int>, greater<int> > pq;
for(auto & ele : scoville)
{
pq.push(ele);
}
int cnt = 0; int mixed = 0; int first = 0; int second = 0;
while(pq.size()!=1)
{
if(pq.top() >= K) break;
first = pq.top();
pq.pop();
second = pq.top();
pq.pop();
mixed = first + second + second;
pq.push(mixed);
cnt++;
}
if(pq.top() < K) return -1;
return cnt == 0 ? -1 : cnt;
}
728x90
๋ฐ์ํ
LIST
'๐ฅ Algorithm || ๋ฌธ์ ํ์ด > PS' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[2017 ํ์คํ์ด] ์ง์ง์ด ์ ๊ฑฐํ๊ธฐ (0) | 2022.07.11 |
---|---|
[2019 ์นด์นด์ค ๊ฐ๋ฐ์ ๊ฒจ์ธ ์ธํด์ญ] ํํ (0) | 2022.07.11 |
[ํ๋ก๊ทธ๋๋จธ์ค] ์ ํ๋ฒํธ ๋ชฉ๋ก (0) | 2022.07.08 |
[2020 KAKAO BLIND RECRUITMENT] ๊ดํธ ๋ณํ (0) | 2022.07.08 |
[2019 KAKAO BLIND RECRUITMENT] ์คํ์ฑํ ๋ฐฉ (0) | 2022.07.07 |
Comments