<p>Welcome to the Editorial of <a href="https://tinyurl.com/IPCjunior-1-25-26"><b>IPC junior-1 (2025–26)</b></a>.</p>↵
↵
<a href="https://mirror.codeforces.com/gym/641211/problem/A"><h2>A. Choco-Coco</h2></a>↵
<b>Author: </b>[user:Aditya_Dave,2025-10-16], [user:202401457,2025-10-16], [user:billu_1903,2025-10-16]↵
↵
<spoiler summary="Problem Tags"> Math, Implementation </spoiler>↵
↵
<spoiler summary="Solution">↵
We are given an array of size <i>n</i> with total sum <i>S</i>. ↵
If <i>S</i> is divisible by <i>n</i>, the array is already balanced and the answer is "YES". ↵
Otherwise, we can try deleting one element <i>a[i]</i>. After deletion, the new sum becomes <i>S − a[i]</i> and the size becomes <i>n − 1</i>. ↵
To be balanced, <i>(S − a[i])</i> must be divisible by <i>(n − 1)</i>, which means <i>a[i] % (n − 1) == S % (n − 1)</i>. ↵
We just need to check if such an element exists.↵
</spoiler>↵
↵
<spoiler summary="Code"><pre><code class="language-c">#include <stdio.h>↵
↵
int main() {↵
int x, y, n;↵
↵
// Input number of chocolates of type x and y↵
scanf("%d %d", &x, &y);↵
↵
// Input number of children↵
scanf("%d", &n);↵
↵
// Check if total chocolates are enough for all children↵
if ((x + y) >= n) {↵
printf("YES\n");↵
} else {↵
printf("NO\n");↵
}↵
↵
return 0;↵
}↵
</code></pre></spoiler>↵
↵
↵
<a href="https://mirror.codeforces.com/gym/641211/problem/B"><h2>B. Strongest Digit</h2></a>↵
<b>Author: </b>[user:Raj_Patel_7807,2025-10-16]↵
↵
<spoiler summary="Problem Tags"> Math, Implementation </spoiler>↵
↵
<spoiler summary="Solution">↵
We are given an array of size <i>n</i> with total sum <i>S</i>. ↵
If <i>S</i> is divisible by <i>n</i>, the array is already balanced and the answer is "YES". ↵
Otherwise, we can try deleting one element <i>a[i]</i>. After deletion, the new sum becomes <i>S − a[i]</i> and the size becomes <i>n − 1</i>. ↵
To be balanced, <i>(S − a[i])</i> must be divisible by <i>(n − 1)</i>, which means <i>a[i] % (n − 1) == S % (n − 1)</i>. ↵
We just need to check if such an element exists.↵
</spoiler>↵
↵
<spoiler summary="Code"><pre><code class="language-c">#include <stdio.h>↵
↵
int main() {↵
int t;↵
scanf("%d", &t); // taking the number of test cases↵
↵
while (t--) { // loop runs for each test case↵
long long n;↵
scanf("%lld", &n); // input number for the current test case↵
↵
int maxi = 0;↵
while (n > 0) {↵
int rem = n % 10; // extract last digit↵
if (rem > maxi) {↵
maxi = rem; // update maximum digit↵
}↵
n /= 10; // remove last digit↵
}↵
printf("%d\n", maxi); // print maximum digit↵
}↵
return 0;↵
}↵
</code></pre></spoiler>↵
↵
↵
<a href="https://mirror.codeforces.com/gym/641211/problem/C1"><h2>C1. Contest Glitch (Easy Version)</h2></a>↵
<b>Author: </b>[user:Raj_Patel_7807,2025-10-16]↵
↵
<spoiler summary="Problem Tags"> Array, Implementation, Brute Force </spoiler>↵
↵
<spoiler summary="Solution">↵
We are given an array of size <i>n</i> with total sum <i>S</i>. ↵
If <i>S</i> is divisible by <i>n</i>, the array is already balanced and the answer is "YES". ↵
Otherwise, we can try deleting one element <i>a[i]</i>. After deletion, the new sum becomes <i>S − a[i]</i> and the size becomes <i>n − 1</i>. ↵
To be balanced, <i>(S − a[i])</i> must be divisible by <i>(n − 1)</i>, which means <i>a[i] % (n − 1) == S % (n − 1)</i>. ↵
We just need to check if such an element exists.↵
</spoiler>↵
↵
<spoiler summary="Code"><pre><code class="language-c">#include <stdio.h>↵
↵
int main() {↵
int n;↵
scanf("%d", &n); // Read the size of the array↵
↵
int a[n]; // Declare an array of size n↵
↵
// Read the array elements↵
for (int i = 0; i < n; i++) {↵
scanf("%d", &a[i]);↵
}↵
↵
// Check for the smallest missing number in range 0 to 100↵
for (int i = 0; i <= 100; i++) {↵
int found = 0; // Flag to check if current number i exists in array↵
↵
// Search for current number i in the array↵
for (int j = 0; j < n; j++) {↵
if (a[j] == i) {↵
found = 1; // Number found in array↵
break; // No need to check further↵
}↵
}↵
↵
// If number i is not found in the array↵
if (!found) {↵
printf("%d\n", i); // Print the missing number↵
return 0; // Exit the program↵
}↵
}↵
↵
return 0;↵
}↵
</code></pre></spoiler>↵
↵
↵
<a href="https://mirror.codeforces.com/gym/641211/problem/C2"><h2>C2. Contest Glitch (Hard Version)</h2></a>↵
<b>Author: </b>[user:Raj_Patel_7807,2025-10-16]↵
↵
<spoiler summary="Problem Tags"> Array, Implementation, Hashing </spoiler>↵
↵
<spoiler summary="Solution">↵
We are given an array of size <i>n</i> with total sum <i>S</i>. ↵
If <i>S</i> is divisible by <i>n</i>, the array is already balanced and the answer is "YES". ↵
Otherwise, we can try deleting one element <i>a[i]</i>. After deletion, the new sum becomes <i>S − a[i]</i> and the size becomes <i>n − 1</i>. ↵
To be balanced, <i>(S − a[i])</i> must be divisible by <i>(n − 1)</i>, which means <i>a[i] % (n − 1) == S % (n − 1)</i>. ↵
We just need to check if such an element exists.↵
</spoiler>↵
↵
<spoiler summary="Code"><pre><code class="language-c">#include <stdio.h>↵
↵
int main() {↵
int n;↵
scanf("%d", &n);↵
↵
int a[n];↵
int present[100001] = {0}; // Array to mark which numbers exist↵
↵
// Read array and mark present numbers↵
for (int i = 0; i < n; i++) {↵
scanf("%d", &a[i]);↵
present[a[i]] = 1;↵
}↵
↵
// Find the smallest number not present in the array (MEX)↵
int mex = 0;↵
while (present[mex]) {↵
mex++;↵
}↵
↵
printf("%d\n", mex); // Print MEX↵
return 0;↵
}↵
</code></pre></spoiler>↵
↵
↵
<a href="https://mirror.codeforces.com/gym/641211/problem/D"><h2>D. Can Mahek Cheat ?</h2></a>↵
<b>Author: </b>[user:Dynamo_14,2025-10-16]↵
↵
<spoiler summary="Problem Tags"> 2D-Array, Math, Implementation </spoiler>↵
↵
<spoiler summary="Solution">↵
We are given an array of size <i>n</i> with total sum <i>S</i>. ↵
If <i>S</i> is divisible by <i>n</i>, the array is already balanced and the answer is "YES". ↵
Otherwise, we can try deleting one element <i>a[i]</i>. After deletion, the new sum becomes <i>S − a[i]</i> and the size becomes <i>n − 1</i>. ↵
To be balanced, <i>(S − a[i])</i> must be divisible by <i>(n − 1)</i>, which means <i>a[i] % (n − 1) == S % (n − 1)</i>. ↵
We just need to check if such an element exists.↵
</spoiler>↵
↵
<spoiler summary="Code"><pre><code class="language-c">#include <stdio.h>↵
↵
int main() {↵
int s, n, m;↵
↵
// Read Mahek's seat number, rows, and columns↵
scanf("%d %d %d", &s, &n, &m);↵
↵
// Calculate Mahek's seat position (row and column)↵
// Seat numbering is row-wise starting from 1↵
int mahek_row = (s — 1) / m + 1;↵
int mahek_col = (s — 1) % m + 1;↵
↵
// Read first invigilator's region↵
int r1, c1, r2, c2;↵
scanf("%d %d %d %d", &r1, &c1, &r2, &c2);↵
↵
// Read second invigilator's region ↵
int r3, c3, r4, c4;↵
scanf("%d %d %d %d", &r3, &c3, &r4, &c4);↵
↵
// Check if Mahek is in first invigilator's region↵
int in_first = (mahek_row >= r1 && mahek_row <= r2 && ↵
mahek_col >= c1 && mahek_col <= c2);↵
↵
// Check if Mahek is in second invigilator's region↵
int in_second = (mahek_row >= r3 && mahek_row <= r4 && ↵
mahek_col >= c3 && mahek_col <= c4);↵
↵
// If Mahek is NOT in either region, he can cheat safely↵
if (!in_first && !in_second) {↵
printf("Yes\n");↵
} else {↵
printf("No\n");↵
}↵
↵
return 0;↵
}↵
</code></pre></spoiler>↵
↵
↵
<a href="https://mirror.codeforces.com/gym/641211/problem/E"><h2>E. Minimal K-Sum</h2></a>↵
<b>Author: </b>[user:Raze07,2025-10-16]↵
↵
<spoiler summary="Problem Tags"> Math, Hashing, Implementation, Prefix sum, Sliding Window </spoiler>↵
↵
<spoiler summary="Solution">↵
We are given an array of size <i>n</i> with total sum <i>S</i>. ↵
If <i>S</i> is divisible by <i>n</i>, the array is already balanced and the answer is "YES". ↵
Otherwise, we can try deleting one element <i>a[i]</i>. After deletion, the new sum becomes <i>S − a[i]</i> and the size becomes <i>n − 1</i>. ↵
To be balanced, <i>(S − a[i])</i> must be divisible by <i>(n − 1)</i>, which means <i>a[i] % (n − 1) == S % (n − 1)</i>. ↵
We just need to check if such an element exists.↵
</spoiler>↵
↵
<spoiler summary="Code"><pre><code class="language-cpp">#include <bits/stdc++.h>↵
using namespace std;↵
↵
int main() {↵
ios_base::sync_with_stdio(false);↵
cin.tie(NULL);↵
↵
int t;↵
cin >> t; // Number of test cases↵
↵
while (t--) {↵
int n;↵
long long k;↵
cin >> n >> k;↵
↵
vector<long long> a(n);↵
for (int i = 0; i < n; i++) {↵
cin >> a[i]; // Input array elements↵
}↵
↵
// Map to store the last seen index for each prefix sum remainder modulo k↵
map<long long, int> seen;↵
seen[0] = -1; // Initialize remainder 0 at index -1↵
↵
long long prefix = 0;↵
int ans = n + 1; // Initialize with a value larger than maximum possible↵
↵
for (int i = 0; i < n; i++) {↵
prefix = (prefix + a[i]) % k;↵
↵
// Normalize remainder to be in range [0, k-1]↵
long long rem = prefix;↵
if (rem < 0) rem += k;↵
↵
// Check if we've seen this remainder before↵
if (seen.find(rem) != seen.end()) {↵
int prev = seen[rem];↵
ans = min(ans, i - prev); // Update minimum subarray length↵
}↵
↵
// Update the last seen index for this remainder↵
seen[rem] = i;↵
}↵
↵
// Output result↵
if (ans == n + 1) {↵
cout << -1 << "\n"; // No valid subarray found↵
} else {↵
cout << ans << "\n"; // Minimum length of subarray divisible by k↵
}↵
}↵
↵
return 0;↵
}↵
</code></pre></spoiler>↵
↵
↵
<a href="https://mirror.codeforces.com/gym/641211/problem/A"><h2>A. Choco-Coco</h2></a>↵
<b>Author: </b>[user:Aditya_Dave,2025-10-16], [user:202401457,2025-10-16], [user:billu_1903,2025-10-16]↵
↵
<spoiler summary="Problem Tags"> Math, Implementation </spoiler>↵
↵
<spoiler summary="Solution">↵
We are given an array of size <i>n</i> with total sum <i>S</i>. ↵
If <i>S</i> is divisible by <i>n</i>, the array is already balanced and the answer is "YES". ↵
Otherwise, we can try deleting one element <i>a[i]</i>. After deletion, the new sum becomes <i>S − a[i]</i> and the size becomes <i>n − 1</i>. ↵
To be balanced, <i>(S − a[i])</i> must be divisible by <i>(n − 1)</i>, which means <i>a[i] % (n − 1) == S % (n − 1)</i>. ↵
We just need to check if such an element exists.↵
</spoiler>↵
↵
<spoiler summary="Code"><pre><code class="language-c">#include <stdio.h>↵
↵
int main() {↵
int x, y, n;↵
↵
// Input number of chocolates of type x and y↵
scanf("%d %d", &x, &y);↵
↵
// Input number of children↵
scanf("%d", &n);↵
↵
// Check if total chocolates are enough for all children↵
if ((x + y) >= n) {↵
printf("YES\n");↵
} else {↵
printf("NO\n");↵
}↵
↵
return 0;↵
}↵
</code></pre></spoiler>↵
↵
↵
<a href="https://mirror.codeforces.com/gym/641211/problem/B"><h2>B. Strongest Digit</h2></a>↵
<b>Author: </b>[user:Raj_Patel_7807,2025-10-16]↵
↵
<spoiler summary="Problem Tags"> Math, Implementation </spoiler>↵
↵
<spoiler summary="Solution">↵
We are given an array of size <i>n</i> with total sum <i>S</i>. ↵
If <i>S</i> is divisible by <i>n</i>, the array is already balanced and the answer is "YES". ↵
Otherwise, we can try deleting one element <i>a[i]</i>. After deletion, the new sum becomes <i>S − a[i]</i> and the size becomes <i>n − 1</i>. ↵
To be balanced, <i>(S − a[i])</i> must be divisible by <i>(n − 1)</i>, which means <i>a[i] % (n − 1) == S % (n − 1)</i>. ↵
We just need to check if such an element exists.↵
</spoiler>↵
↵
<spoiler summary="Code"><pre><code class="language-c">#include <stdio.h>↵
↵
int main() {↵
int t;↵
scanf("%d", &t); // taking the number of test cases↵
↵
while (t--) { // loop runs for each test case↵
long long n;↵
scanf("%lld", &n); // input number for the current test case↵
↵
int maxi = 0;↵
while (n > 0) {↵
int rem = n % 10; // extract last digit↵
if (rem > maxi) {↵
maxi = rem; // update maximum digit↵
}↵
n /= 10; // remove last digit↵
}↵
printf("%d\n", maxi); // print maximum digit↵
}↵
return 0;↵
}↵
</code></pre></spoiler>↵
↵
↵
<a href="https://mirror.codeforces.com/gym/641211/problem/C1"><h2>C1. Contest Glitch (Easy Version)</h2></a>↵
<b>Author: </b>[user:Raj_Patel_7807,2025-10-16]↵
↵
<spoiler summary="Problem Tags"> Array, Implementation, Brute Force </spoiler>↵
↵
<spoiler summary="Solution">↵
We are given an array of size <i>n</i> with total sum <i>S</i>. ↵
If <i>S</i> is divisible by <i>n</i>, the array is already balanced and the answer is "YES". ↵
Otherwise, we can try deleting one element <i>a[i]</i>. After deletion, the new sum becomes <i>S − a[i]</i> and the size becomes <i>n − 1</i>. ↵
To be balanced, <i>(S − a[i])</i> must be divisible by <i>(n − 1)</i>, which means <i>a[i] % (n − 1) == S % (n − 1)</i>. ↵
We just need to check if such an element exists.↵
</spoiler>↵
↵
<spoiler summary="Code"><pre><code class="language-c">#include <stdio.h>↵
↵
int main() {↵
int n;↵
scanf("%d", &n); // Read the size of the array↵
↵
int a[n]; // Declare an array of size n↵
↵
// Read the array elements↵
for (int i = 0; i < n; i++) {↵
scanf("%d", &a[i]);↵
}↵
↵
// Check for the smallest missing number in range 0 to 100↵
for (int i = 0; i <= 100; i++) {↵
int found = 0; // Flag to check if current number i exists in array↵
↵
// Search for current number i in the array↵
for (int j = 0; j < n; j++) {↵
if (a[j] == i) {↵
found = 1; // Number found in array↵
break; // No need to check further↵
}↵
}↵
↵
// If number i is not found in the array↵
if (!found) {↵
printf("%d\n", i); // Print the missing number↵
return 0; // Exit the program↵
}↵
}↵
↵
return 0;↵
}↵
</code></pre></spoiler>↵
↵
↵
<a href="https://mirror.codeforces.com/gym/641211/problem/C2"><h2>C2. Contest Glitch (Hard Version)</h2></a>↵
<b>Author: </b>[user:Raj_Patel_7807,2025-10-16]↵
↵
<spoiler summary="Problem Tags"> Array, Implementation, Hashing </spoiler>↵
↵
<spoiler summary="Solution">↵
We are given an array of size <i>n</i> with total sum <i>S</i>. ↵
If <i>S</i> is divisible by <i>n</i>, the array is already balanced and the answer is "YES". ↵
Otherwise, we can try deleting one element <i>a[i]</i>. After deletion, the new sum becomes <i>S − a[i]</i> and the size becomes <i>n − 1</i>. ↵
To be balanced, <i>(S − a[i])</i> must be divisible by <i>(n − 1)</i>, which means <i>a[i] % (n − 1) == S % (n − 1)</i>. ↵
We just need to check if such an element exists.↵
</spoiler>↵
↵
<spoiler summary="Code"><pre><code class="language-c">#include <stdio.h>↵
↵
int main() {↵
int n;↵
scanf("%d", &n);↵
↵
int a[n];↵
int present[100001] = {0}; // Array to mark which numbers exist↵
↵
// Read array and mark present numbers↵
for (int i = 0; i < n; i++) {↵
scanf("%d", &a[i]);↵
present[a[i]] = 1;↵
}↵
↵
// Find the smallest number not present in the array (MEX)↵
int mex = 0;↵
while (present[mex]) {↵
mex++;↵
}↵
↵
printf("%d\n", mex); // Print MEX↵
return 0;↵
}↵
</code></pre></spoiler>↵
↵
↵
<a href="https://mirror.codeforces.com/gym/641211/problem/D"><h2>D. Can Mahek Cheat ?</h2></a>↵
<b>Author: </b>[user:Dynamo_14,2025-10-16]↵
↵
<spoiler summary="Problem Tags"> 2D-Array, Math, Implementation </spoiler>↵
↵
<spoiler summary="Solution">↵
We are given an array of size <i>n</i> with total sum <i>S</i>. ↵
If <i>S</i> is divisible by <i>n</i>, the array is already balanced and the answer is "YES". ↵
Otherwise, we can try deleting one element <i>a[i]</i>. After deletion, the new sum becomes <i>S − a[i]</i> and the size becomes <i>n − 1</i>. ↵
To be balanced, <i>(S − a[i])</i> must be divisible by <i>(n − 1)</i>, which means <i>a[i] % (n − 1) == S % (n − 1)</i>. ↵
We just need to check if such an element exists.↵
</spoiler>↵
↵
<spoiler summary="Code"><pre><code class="language-c">#include <stdio.h>↵
↵
int main() {↵
int s, n, m;↵
↵
// Read Mahek's seat number, rows, and columns↵
scanf("%d %d %d", &s, &n, &m);↵
↵
// Calculate Mahek's seat position (row and column)↵
// Seat numbering is row-wise starting from 1↵
int mahek_row = (s — 1) / m + 1;↵
int mahek_col = (s — 1) % m + 1;↵
↵
// Read first invigilator's region↵
int r1, c1, r2, c2;↵
scanf("%d %d %d %d", &r1, &c1, &r2, &c2);↵
↵
// Read second invigilator's region ↵
int r3, c3, r4, c4;↵
scanf("%d %d %d %d", &r3, &c3, &r4, &c4);↵
↵
// Check if Mahek is in first invigilator's region↵
int in_first = (mahek_row >= r1 && mahek_row <= r2 && ↵
mahek_col >= c1 && mahek_col <= c2);↵
↵
// Check if Mahek is in second invigilator's region↵
int in_second = (mahek_row >= r3 && mahek_row <= r4 && ↵
mahek_col >= c3 && mahek_col <= c4);↵
↵
// If Mahek is NOT in either region, he can cheat safely↵
if (!in_first && !in_second) {↵
printf("Yes\n");↵
} else {↵
printf("No\n");↵
}↵
↵
return 0;↵
}↵
</code></pre></spoiler>↵
↵
↵
<a href="https://mirror.codeforces.com/gym/641211/problem/E"><h2>E. Minimal K-Sum</h2></a>↵
<b>Author: </b>[user:Raze07,2025-10-16]↵
↵
<spoiler summary="Problem Tags"> Math, Hashing, Implementation, Prefix sum, Sliding Window </spoiler>↵
↵
<spoiler summary="Solution">↵
We are given an array of size <i>n</i> with total sum <i>S</i>. ↵
If <i>S</i> is divisible by <i>n</i>, the array is already balanced and the answer is "YES". ↵
Otherwise, we can try deleting one element <i>a[i]</i>. After deletion, the new sum becomes <i>S − a[i]</i> and the size becomes <i>n − 1</i>. ↵
To be balanced, <i>(S − a[i])</i> must be divisible by <i>(n − 1)</i>, which means <i>a[i] % (n − 1) == S % (n − 1)</i>. ↵
We just need to check if such an element exists.↵
</spoiler>↵
↵
<spoiler summary="Code"><pre><code class="language-cpp">#include <bits/stdc++.h>↵
using namespace std;↵
↵
int main() {↵
ios_base::sync_with_stdio(false);↵
cin.tie(NULL);↵
↵
int t;↵
cin >> t; // Number of test cases↵
↵
while (t--) {↵
int n;↵
long long k;↵
cin >> n >> k;↵
↵
vector<long long> a(n);↵
for (int i = 0; i < n; i++) {↵
cin >> a[i]; // Input array elements↵
}↵
↵
// Map to store the last seen index for each prefix sum remainder modulo k↵
map<long long, int> seen;↵
seen[0] = -1; // Initialize remainder 0 at index -1↵
↵
long long prefix = 0;↵
int ans = n + 1; // Initialize with a value larger than maximum possible↵
↵
for (int i = 0; i < n; i++) {↵
prefix = (prefix + a[i]) % k;↵
↵
// Normalize remainder to be in range [0, k-1]↵
long long rem = prefix;↵
if (rem < 0) rem += k;↵
↵
// Check if we've seen this remainder before↵
if (seen.find(rem) != seen.end()) {↵
int prev = seen[rem];↵
ans = min(ans, i - prev); // Update minimum subarray length↵
}↵
↵
// Update the last seen index for this remainder↵
seen[rem] = i;↵
}↵
↵
// Output result↵
if (ans == n + 1) {↵
cout << -1 << "\n"; // No valid subarray found↵
} else {↵
cout << ans << "\n"; // Minimum length of subarray divisible by k↵
}↵
}↵
↵
return 0;↵
}↵
</code></pre></spoiler>↵
↵




