转化为求最多和为0的子数组,其实就是前缀和的次数
#include<iostream>
#include<iomanip>
#include<string.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<cstdio>
#include<string>
using namespace std;
map<long long int, long long int> m;
int a[100001];
int max(int a, int b) {
return a > b ? a : b;
}
int main() {
int c;
cin >> c;
int res = 0;
long long int sum = 0;
for (int i = 0; i < c; ++i) {
cin >> a[i];
sum += a[i];
m[sum]++;
res = max(m[sum], res);
}
cout << c - res<<endl;
system("pause");
}