-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKillMonsters.cpp
53 lines (52 loc) · 963 Bytes
/
KillMonsters.cpp
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
42
43
44
45
46
47
48
49
50
51
52
53
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
int main()
{
int n;
cin>>n;
vector <int> d(n);
priority_queue <int> k;
for(int i=0;i<n;i++)
cin>>d[i];
int m,kill=0;
cin>>m;
int x;
cin>>x;
for(int i=0;i<n;i++)
{
if(d[i]<=0)
{
x-=d[i];
kill++;
}
else
{
if(x>0)
{
x-=d[i];
kill++;
k.push(d[i]);
}
if(x<=0)
{
if(m>0)
{
m--;
int t=k.top();
k.pop();
x+=t;
}
else
{
if(x<0)
kill--;
break;
}
}
}
}
cout<<kill;
return 0;
}