forked from iRupam/NewtonSchoolInfinityJune21
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKillTheMonster.java
More file actions
53 lines (44 loc) · 1.51 KB
/
KillTheMonster.java
File metadata and controls
53 lines (44 loc) · 1.51 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
47
48
49
50
51
52
53
package InfinityJune21.HackathonDoubtSessionJul4;
import java.util.Arrays;
import java.util.Scanner;
public class KillTheMonster {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int N = scanner.nextInt();
int D = scanner.nextInt();
int H = scanner.nextInt();
int attackWeight[][] = new int[2][N];
for(int i = 0; i < N; i++) {
attackWeight[0][i] = scanner.nextInt();
}
for(int i = 0; i < N; i++) {
int weight = scanner.nextInt();
if(weight > D) {
attackWeight[0][i] = 0;
attackWeight[1][i] = 0;
}
else {
//totalAttackingPower = totalAttackingPower + attackWeight[0][i];
attackWeight[1][i] = weight;
}
}
Arrays.sort(attackWeight[0]);
int weaponsCount = 0;
int attackingPowerReached = 0;
for(int i = attackWeight[0].length - 1; i >= 0 ; i--) {
if(attackWeight[0][i] > 0) {
attackingPowerReached = attackingPowerReached + attackWeight[0][i];
weaponsCount = weaponsCount + 1;
if(attackingPowerReached >= H) {
break;
}
}
}
if(attackingPowerReached >= H) {
System.out.println(weaponsCount);
}
else {
System.out.println("-1");
}
}
}