ac
2025-07-09 22:08:49
发布于:广东
6阅读
0回复
0点赞
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int T, n, a[N];
bool check(int x) {
int res = 0;
for(int i = 1; i <= n; i++) {
if(res + a[i] <= x) res += a[i];
else if(res != x) return false;
else res = a[i];
}
return true;
}
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
for(cin >> T; T; T--) {
cin >> n;
int sum = 0;
for(int i = 1; i <= n; i++)
cin >> a[i], sum += a[i];
for(int i = 0; i <= sum; i++) {
if((i == 0 || sum % i == 0) && check(i)) {
cout << (i == 0 ? 0 : n - sum / i) << endl;
break;
}
}
}
return 0;
}
这里空空如也
有帮助,赞一个