forked from the-moonLight0/Hactober-fest-2021
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PointOfImpact.java
57 lines (55 loc) · 1.45 KB
/
PointOfImpact.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
47
48
49
50
51
52
53
54
55
56
57
// This is a codechef problem.
package CodeChef;
import java.util.*;
public class PointOfImpact {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int t = s.nextInt();
while(t-- !=0) {
int n = s.nextInt();
int k = s.nextInt();
int x = s.nextInt();
int y = s.nextInt();
if(x==y) {
System.out.println(n + " " + n);
}
else {
if(x>y) {
List<Integer> list1 = new ArrayList<Integer>(4);
list1.add(0,x-y);
list1.add(1,n);
list1.add(2,n+y-x);
list1.add(3,0);
List<Integer> list2 = new ArrayList<Integer>(4);
list2.add(0,0);
list2.add(1,n+y-x);
list2.add(2,n);
list2.add(3,x-y);
int num=k%4;
System.out.print(list1.get(num));
System.out.print(" ");
System.out.print(list2.get(num));
System.out.println();
}
else {
List<Integer> numbers1 = new ArrayList<Integer>(4);
numbers1.add(0,0);
numbers1.add(1,n+x-y);
numbers1.add(2,n);
numbers1.add(3,y-x);
List<Integer> numbers2 = new ArrayList<Integer>(4);
numbers2.add(0,y-x);
numbers2.add(1,n);
numbers2.add(2,n+x-y);
numbers2.add(3,0);
int num=k%4;
System.out.print(numbers1.get(num));
System.out.print(" ");
System.out.print(numbers2.get(num));
System.out.println();
}
}
}
s.close();
}
}