Welcome to the Editorial of IPC junior-1 (2025–26).
A. Choco-Coco
Author:Aditya_Dave, 202401457, billu_1903
Problem Tags
Math, Implementation
Solution
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.
Code
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t; cin >> t;
while (t--) {
int n; cin >> n;
vector<int> a(n);
long long sum = 0;
for (int &x : a) cin >> x, sum += x;
if (sum % n == 0) {
cout << "YES\n";
continue;
}
long long rem = sum % (n - 1);
bool ok = false;
for (int x : a)
if (x % (n - 1) == rem)
ok = true;
cout << (ok ? "YES\n" : "NO\n");
}
}



