Skip to content

Commit 53427a9

Browse files
committed
solution of problem B in Codechef Sept Starters 2021
1 parent 4a0e535 commit 53427a9

File tree

1 file changed

+94
-0
lines changed
  • Codechef/StartersSept2021

1 file changed

+94
-0
lines changed

Codechef/StartersSept2021/B.java

+94
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
package StartersSept2021;
2+
3+
import java.io.PrintWriter;
4+
import java.io.BufferedReader;
5+
import java.io.InputStreamReader;
6+
import java.io.IOException;
7+
import java.util.StringTokenizer;
8+
9+
public class B {
10+
11+
public static void main(String[] args) {
12+
13+
FastReader sc = new FastReader();
14+
PrintWriter out = new PrintWriter(System.out);
15+
16+
int t = sc.nextInt();
17+
18+
for (int tt = 0; tt < t; tt++) {
19+
20+
int N = sc.nextInt(); // max tastiness, O TO N
21+
int S = sc.nextInt(); // sum of T1 and T2
22+
23+
int ans = solveTask(N, S);
24+
System.out.println(ans);
25+
}
26+
out.close();
27+
}
28+
29+
private static int solveTask(int N, int S) {
30+
31+
int diff = 0;
32+
33+
for (int i = 0; i <= N; i++) {
34+
35+
int rest = S - i;
36+
37+
if (rest <= N && rest >= 0) {
38+
diff = Math.abs(i - rest);
39+
}
40+
}
41+
42+
return diff;
43+
}
44+
45+
static class FastReader {
46+
BufferedReader br;
47+
StringTokenizer st;
48+
49+
FastReader() {
50+
br = new BufferedReader(new InputStreamReader(System.in));
51+
}
52+
53+
String next() {
54+
while (st == null || !st.hasMoreElements()) {
55+
try {
56+
st = new StringTokenizer(br.readLine());
57+
} catch (IOException e) {
58+
e.printStackTrace();
59+
}
60+
}
61+
return st.nextToken();
62+
}
63+
64+
int nextInt() {
65+
return Integer.parseInt(next());
66+
}
67+
68+
long nextLong() {
69+
return Long.parseLong(next());
70+
}
71+
72+
double nextDouble() {
73+
return Double.parseDouble(next());
74+
}
75+
76+
String nextLine() {
77+
String str = "";
78+
try {
79+
str = br.readLine();
80+
} catch (IOException e) {
81+
e.printStackTrace();
82+
}
83+
return str;
84+
}
85+
86+
int[] readArray(int n) {
87+
int[] temparr = new int[n];
88+
for (int i = 0; i < n; i++) {
89+
temparr[i] = nextInt();
90+
}
91+
return temparr;
92+
}
93+
}
94+
}

0 commit comments

Comments
 (0)