๋ฌธ์
์ฝ๋
#include <string>
#include <vector>
#include <queue>
using namespace std;
int solution(vector<int> scoville, int K) {
int answer = 0;
priority_queue<int,vector<int>,greater<int>>pq;
for(int i=0; i<scoville.size(); i++){
pq.push(scoville[i]);
}
while(pq.top()<K){
if(pq.size()==2){
int a=pq.top(); pq.pop();
int b=pq.top(); pq.pop();
int mix=a+(b*2);
if(mix<K){
answer=-1;
break;
}
else{
answer++;
break;
}
}
else if(pq.size()!=1){
answer++;
int a=pq.top(); pq.pop();
int b=pq.top(); pq.pop();
int mix=a+(b*2);
pq.push(mix);
}
}
return answer;
}
'Algorithm ๐ง๐ปโ๐ป > ํ๋ก๊ทธ๋๋จธ์ค(Programmers)' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[c++] ํ๋ก๊ทธ๋๋จธ์ค - ๋ชจ์๊ณ ์ฌ( Level 1) (0) | 2021.10.21 |
---|---|
[c++] ํ๋ก๊ทธ๋๋จธ์ค - ๋ก๋์ ์ต๊ณ ์์์ ์ต์ ์์( Level 1) (0) | 2021.10.20 |
[c++] ํ๋ก๊ทธ๋๋จธ์ค - ๋ ๊ฐ ๋ฝ์์ ๋ํ๊ธฐ( Level 1) (0) | 2021.10.20 |
[c++] ํ๋ก๊ทธ๋๋จธ์ค - ๋จ์ฒด์ฌ์ง ์ฐ๊ธฐ( Level 2, 2017 ์นด์นด์ค์ฝ๋ ๋ณธ์ ) (0) | 2021.10.20 |
[c++] ํ๋ก๊ทธ๋๋จธ์ค - ๋จ์ด๋ณํ( Level 3) (0) | 2021.10.20 |
[c++] ํ๋ก๊ทธ๋๋จธ์ค - ๋คํธ์ํฌ( Level 3) (0) | 2021.10.20 |
๋๊ธ