Skip to content

Commit f3046e9

Browse files
Create Fight with Monsters.cpp
1 parent 861f8e1 commit f3046e9

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#include <iostream>
2+
#include <vector>
3+
#include <algorithm>
4+
5+
using namespace std;
6+
7+
int ceil(int a, int b)
8+
{
9+
return (a/b) + (a%b != 0);
10+
}
11+
12+
int main()
13+
{
14+
int no_of_elements, attack, opponent_attack, secrets;
15+
cin >> no_of_elements >> attack >> opponent_attack >> secrets;
16+
17+
vector <int> H(no_of_elements + 1);
18+
for(int i = 1; i <= no_of_elements; i++)
19+
{
20+
cin >> H[i];
21+
}
22+
23+
vector <int> skips_required(no_of_elements + 1, 0);
24+
for(int i = 1; i <= no_of_elements; i++)
25+
{
26+
H[i] %= (attack + opponent_attack);
27+
28+
if(H[i] == 0)
29+
{
30+
H[i] = (attack + opponent_attack);
31+
}
32+
33+
H[i] = max(H[i] - attack, 0);
34+
35+
skips_required[i] = ceil(H[i], attack);
36+
}
37+
38+
sort(skips_required.begin(), skips_required.end());
39+
40+
long long total_skips = 0, points = 0;
41+
for(int i = 1; i <= no_of_elements; i++)
42+
{
43+
if(total_skips + skips_required[i] > secrets)
44+
{
45+
break;
46+
}
47+
48+
total_skips += skips_required[i];
49+
50+
points++;
51+
}
52+
53+
cout << points << "\n";
54+
return 0;
55+
}

0 commit comments

Comments
 (0)