-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFightTheMonsters.java
More file actions
executable file
·46 lines (45 loc) · 1.19 KB
/
Copy pathFightTheMonsters.java
File metadata and controls
executable file
·46 lines (45 loc) · 1.19 KB
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
import java.io.*;
import java.util.*;
import java.math.*;
import java.text.*;
class FightTheMonsters
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
int numberOfMonsters;
int blasterPower;
int seconds;
numberOfMonsters = in.nextInt();
blasterPower = in.nextInt();
seconds = in.nextInt();
int[] monsterPowerLevel = new int[numberOfMonsters];
for (int i = 0; i < numberOfMonsters; i++)
{
monsterPowerLevel[i] = in.nextInt();
}
Arrays.sort(monsterPowerLevel);
int monsterIndex = 0;
int numberOfMonsterKilled = 0;
int timeLeft = seconds;
while(true)
{
int timeTaken = monsterPowerLevel[monsterIndex] / blasterPower;
if (monsterPowerLevel[monsterIndex] % blasterPower != 0)
{
timeTaken = timeTaken + 1;
}
timeLeft = timeLeft - timeTaken;
if (timeLeft < 0)
{
break;
}
else
{
numberOfMonsterKilled = numberOfMonsterKilled + 1;
monsterIndex = monsterIndex + 1;
}
}
System.out.println(numberOfMonsterKilled);
}
}