Welcome to the Editorial of IPC junior-1 (2025–26).
A. Choco-Coco
Author: Aditya_Dave, Femm_12, Yashvi_1903
Math, Implementation
We are given an array of size n with total sum S.
If S is divisible by n, the array is already balanced and the answer is "YES".
Otherwise, we can try deleting one element a[i]. After deletion, the new sum becomes S − a[i] and the size becomes n − 1.
To be balanced, (S − a[i]) must be divisible by (n − 1), which means a[i] % (n − 1) == S % (n − 1).
We just need to check if such an element exists.
#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;
}
B. Strongest Digit
Author: Raj_Patel_7807
Math, Implementation
We are given an array of size n with total sum S.
If S is divisible by n, the array is already balanced and the answer is "YES".
Otherwise, we can try deleting one element a[i]. After deletion, the new sum becomes S − a[i] and the size becomes n − 1.
To be balanced, (S − a[i]) must be divisible by (n − 1), which means a[i] % (n − 1) == S % (n − 1).
We just need to check if such an element exists.
#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;
}
C1. Contest Glitch (Easy Version)
Author: Raj_Patel_7807
Array, Implementation, Brute Force
We are given an array of size n with total sum S.
If S is divisible by n, the array is already balanced and the answer is "YES".
Otherwise, we can try deleting one element a[i]. After deletion, the new sum becomes S − a[i] and the size becomes n − 1.
To be balanced, (S − a[i]) must be divisible by (n − 1), which means a[i] % (n − 1) == S % (n − 1).
We just need to check if such an element exists.
#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;
}
C2. Contest Glitch (Hard Version)
Author: Raj_Patel_7807
Array, Implementation, Hashing
We are given an array of size n with total sum S.
If S is divisible by n, the array is already balanced and the answer is "YES".
Otherwise, we can try deleting one element a[i]. After deletion, the new sum becomes S − a[i] and the size becomes n − 1.
To be balanced, (S − a[i]) must be divisible by (n − 1), which means a[i] % (n − 1) == S % (n − 1).
We just need to check if such an element exists.
#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;
}
D. Can Mahek Cheat ?
Author: Dynamo14
2D-Array, Math, Implementation
We are given an array of size n with total sum S.
If S is divisible by n, the array is already balanced and the answer is "YES".
Otherwise, we can try deleting one element a[i]. After deletion, the new sum becomes S − a[i] and the size becomes n − 1.
To be balanced, (S − a[i]) must be divisible by (n − 1), which means a[i] % (n − 1) == S % (n − 1).
We just need to check if such an element exists.
#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;
}
E. Minimal K-Sum
Author: Raze07
Math, Hashing, Implementation, Prefix sum, Sliding Window
We are given an array of size n with total sum S.
If S is divisible by n, the array is already balanced and the answer is "YES".
Otherwise, we can try deleting one element a[i]. After deletion, the new sum becomes S − a[i] and the size becomes n − 1.
To be balanced, (S − a[i]) must be divisible by (n − 1), which means a[i] % (n − 1) == S % (n − 1).
We just need to check if such an element exists.
#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 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 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;
}



