Editorial of IPC junior — 1 (2025-26)
Difference between en21 and en22, changed 0 character(s)
<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 &lt;stdio.h&gt;↵

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 &lt;stdio.h&gt;↵

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 &lt;stdio.h&gt;↵

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 &lt;stdio.h&gt;↵

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 &lt;stdio.h&gt;↵

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 &mdash; 1) / m + 1;↵
    int mahek_col = (s &mdash; 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 &lt;bits/stdc++.h&gt;↵
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>↵

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en30 English Raj_Patel_7807 2026-01-10 13:27:08 6
en29 English Raj_Patel_7807 2026-01-10 13:26:02 6 Tiny change: 'Patel_7807,2025-10-16]\n\n<spoi' -> 'Patel_7807]\n\n<spoi'
en28 English Raj_Patel_7807 2026-01-10 13:25:31 6 Tiny change: 'l_7807,2025-10-16]\n\n<spoi' -> 'l_7807,2026-01-10]\n\n<spoi'
en27 English Raj_Patel_7807 2025-11-23 23:03:50 10 Tiny change: ' map<long long, int> seen;\n ' -> ' map&lt;long long, int&gt; seen;\n '
en26 English Raj_Patel_7807 2025-10-16 19:46:25 6 Tiny change: 'sent[100001] = {0}; ' -> 'sent[100002] = {0}; '
en25 English Raj_Patel_7807 2025-10-16 19:45:23 851
en24 English Raj_Patel_7807 2025-10-16 19:16:42 3668 Tiny change: 'i>s</i>-1)/<i>m</i>) ' -> 'i>s</i>-1) / <i>m</i>) '
en23 English Raj_Patel_7807 2025-10-16 16:56:13 2898
en22 English Raj_Patel_7807 2025-10-16 16:53:49 0 Raj_Patel_2024, (published)
en21 English Raj_Patel_7807 2025-10-16 16:52:30 0 Raj_Patel_2024,
en20 English Raj_Patel_7807 2025-10-16 16:51:58 2 Raj_Patel_2024,
en19 English Raj_Patel_7807 2025-10-16 16:48:51 45
en18 English Raj_Patel_7807 2025-10-16 16:46:39 8157
en17 English Raj_Patel_7807 2025-10-16 16:27:35 1391 Tiny change: 'uage-cpp">\n#include &' -> 'uage-cpp">#include &'
en16 English Raj_Patel_7807 2025-10-16 16:25:18 11 Tiny change: 'uage-cpp">\n#include &' -> 'uage-cpp">#include &'
en15 English Raj_Patel_7807 2025-10-16 16:24:57 32 Tiny change: 'uage-cpp">\n#include &' -> 'uage-cpp">#include &'
en14 English Raj_Patel_7807 2025-10-16 16:24:29 43 Tiny change: 'uage-cpp">\n#include &' -> 'uage-cpp">#include &'
en13 English Raj_Patel_7807 2025-10-16 16:24:11 2 Tiny change: 'uage-cpp">\n#include &' -> 'uage-cpp">#include &'
en12 English Raj_Patel_7807 2025-10-16 16:23:36 10 Tiny change: 'uage-cpp">\n#include &' -> 'uage-cpp">#include &'
en11 English Raj_Patel_7807 2025-10-16 16:22:58 576 Tiny change: 'uage-cpp">\n#include &' -> 'uage-cpp">#include &'
en10 English Raj_Patel_7807 2025-10-16 16:21:03 2 Tiny change: 'uage-cpp">\n#include &' -> 'uage-cpp">#include &'
en9 English Raj_Patel_7807 2025-10-16 16:19:42 4
en8 English Raj_Patel_7807 2025-10-16 16:18:58 50
en7 English Raj_Patel_7807 2025-10-16 16:17:32 57
en6 English Raj_Patel_7807 2025-10-16 16:16:34 899
en5 English Raj_Patel_7807 2025-10-16 16:14:12 38
en4 English Raj_Patel_7807 2025-10-16 16:12:48 26
en3 English Raj_Patel_7807 2025-10-16 16:12:07 4
en2 English Raj_Patel_7807 2025-10-16 16:11:37 114
en1 English Raj_Patel_7807 2025-10-16 16:09:01 2598 Initial revision (saved to drafts)