-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path230412-3.cpp
More file actions
41 lines (39 loc) · 1011 Bytes
/
230412-3.cpp
File metadata and controls
41 lines (39 loc) · 1011 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <string>
#include <vector>
#include <queue>
using namespace std;
priority_queue<int> pq;
int solution(int n, int k, vector<int> enemy) {
int answer = 0;
for(const int & e: enemy)
{
// 이번 라운드 못깨는 경우
if(n < e)
{
// 지금 나온게 제일 커서 걍 여기다가 쓰는게 이득인 경우
if(k > 0 && (pq.empty() || pq.top() <= e))
{
k--;
answer++;
continue;
}
// 그게 아니라면 이전꺼에서 찾아서 쓰는게 이득임
while(k > 0 && !pq.empty())
{
k--;
n += pq.top();
pq.pop();
if(n >= e) break;
}
// 무적권썼는데도 답이 없는경우
if(n < e) break;
}
if(n >= e)
{
n -= e;
pq.push(e);
}
answer++;
}
return answer;
}