-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCodechef.java
More file actions
43 lines (34 loc) · 1.24 KB
/
Codechef.java
File metadata and controls
43 lines (34 loc) · 1.24 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
import java.util.*;
public class Codechef {
public static void main(String[] args) throws java.lang.Exception {
Scanner sc = new Scanner(System.in);
int T = sc.nextInt(); // Number of test cases
while (T-- > 0) {
int N = sc.nextInt(); // Number of attacks
int X = sc.nextInt(); // Initial skill level
int[] A = new int[N]; // Dodge skill requirements
int[] B = new int[N]; // Parry skill requirements
for (int i = 0; i < N; i++) {
A[i] = sc.nextInt();
}
for (int i = 0; i < N; i++) {
B[i] = sc.nextInt();
}
int M = 0; // Maximum parries
boolean win = true;
for (int i = 0; i < N; i++) {
if (X < A[i]) {
win = false;
break; // Chef loses
} else if (X >= B[i]) {
// Can parry
X--; // Lose 1 skill point
M++; // Increase parry count
}
// else: Only dodge (X >= A[i] && X < B[i])
// Just continue, no change in X
}
System.out.println(win ? M : 0);
}
}
}