第一个题解
2025-11-18 18:02:26
发布于:浙江
0阅读
0回复
0点赞
#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> w(n);
for (int i = 0; i < n; ++i) {
cin >> w[i];
}
int left = 0, right = n - 1;
int sum_left = 0, sum_right = 0;
int max_count = 0;
while (left < right) {
if (sum_left <= sum_right) {
sum_left += w[left];
left++;
} else {
sum_right += w[right];
right--;
}
if (sum_left == sum_right) {
max_count = left + (n - right - 1);
}
}
cout << max_count << '\n';
}
return 0;
}
This is the end of the first anser.
这里空空如也







有帮助,赞一个