Skip to content

Commit 22b664d

Browse files
committed
upsolve: solution of problem C in Codechef Sept Starters 2021
1 parent 53427a9 commit 22b664d

File tree

1 file changed

+85
-0
lines changed
  • Codechef/StartersSept2021

1 file changed

+85
-0
lines changed

Codechef/StartersSept2021/C.java

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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 C {
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+
long N = sc.nextLong();
21+
long S = sc.nextLong();
22+
23+
long totalSum = (N * (N + 1)) / 2;
24+
long diff = totalSum - S;
25+
26+
if (diff >= 1 && diff <= N)
27+
System.out.println(diff);
28+
else
29+
System.out.println(-1);
30+
31+
}
32+
33+
out.close();
34+
}
35+
36+
static class FastReader {
37+
BufferedReader br;
38+
StringTokenizer st;
39+
40+
FastReader() {
41+
br = new BufferedReader(new InputStreamReader(System.in));
42+
}
43+
44+
String next() {
45+
while (st == null || !st.hasMoreElements()) {
46+
try {
47+
st = new StringTokenizer(br.readLine());
48+
} catch (IOException e) {
49+
e.printStackTrace();
50+
}
51+
}
52+
return st.nextToken();
53+
}
54+
55+
int nextInt() {
56+
return Integer.parseInt(next());
57+
}
58+
59+
long nextLong() {
60+
return Long.parseLong(next());
61+
}
62+
63+
double nextDouble() {
64+
return Double.parseDouble(next());
65+
}
66+
67+
String nextLine() {
68+
String str = "";
69+
try {
70+
str = br.readLine();
71+
} catch (IOException e) {
72+
e.printStackTrace();
73+
}
74+
return str;
75+
}
76+
77+
int[] readArray(int n) {
78+
int[] temparr = new int[n];
79+
for (int i = 0; i < n; i++) {
80+
temparr[i] = nextInt();
81+
}
82+
return temparr;
83+
}
84+
}
85+
}

0 commit comments

Comments
 (0)