-
Notifications
You must be signed in to change notification settings - Fork 0
/
A 1275 - Two Rival Students.java
46 lines (38 loc) · 1.08 KB
/
A 1275 - Two Rival Students.java
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.Scanner;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int[][] data = new int[input.nextInt()][4];
for (int i = 0; i < data.length; i++) {
for (int j = 0; j < data[i].length; j++) {
data[i][j] = input.nextInt();
}
}
int m, n, a, b, result;
for (int i = 0; i < data.length; i++) {
result = 0;
m = data[i][0];
n = data[i][1];
a = data[i][2];
b = data[i][3];
if (a < b) {
result = a;
a = b;
b = result;
result = 0;
}
for (int j = 0; j < n; j++) {
if (a == m && b == 1) {
break;
}
if (a < m) {
a++;
} else if (b > 1) {
b--;
}
}
result = a-b;
System.out.println(result);
}
}
}