-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path1.java
More file actions
46 lines (37 loc) · 1.13 KB
/
Copy path1.java
File metadata and controls
46 lines (37 loc) · 1.13 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.util.*;
public class RPGGameQuest {
static class Monster {
int power;
int bonus;
Monster(int power, int bonus) {
this.power = power;
this.bonus = bonus;
}
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int initialExperience = scanner.nextInt();
Monster[] monsters = new Monster[n];
for (int i = 0; i < n; i++) {
int power = scanner.nextInt();
monsters[i] = new Monster(power, 0);
}
for (int i = 0; i < n; i++) {
int bonus = scanner.nextInt();
monsters[i].bonus = bonus;
}
Arrays.sort(monsters, Comparator.comparingInt(m -> m.power));
int defeated = 0;
int experience = initialExperience;
for (Monster monster : monsters) {
if (experience >= monster.power) {
experience += monster.bonus;
defeated++;
} else {
break;
}
}
System.out.println(defeated);
}
}