Skip to content

Commit 6c2c8d8

Browse files
authored
🐜 Study: 더 맵게 (#105)
1 parent 3d50fbd commit 6c2c8d8

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

더 맵게.cc

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include <string>
2+
#include <vector>
3+
#include <set>
4+
5+
using namespace std;
6+
7+
int solution(vector<int> scoville, int K) {
8+
int answer = 0;
9+
multiset<int> s(scoville.begin(), scoville.end());
10+
auto it = s.begin();
11+
while(*s.begin() < K)
12+
{
13+
if(++s.begin() == s.end()) return -1;
14+
int sum = *s.begin() + *++s.begin()*2;
15+
s.erase(s.begin(), ++(++s.begin()));
16+
s.insert(sum);
17+
answer++;
18+
}
19+
20+
return answer;
21+
}

0 commit comments

Comments
 (0)