Skip to content

Instantly share code, notes, and snippets.

@Thiago4532
Last active May 6, 2020 03:54
Show Gist options
  • Select an option

  • Save Thiago4532/2de37125a70b1bed4516b2d5a8d4c4ec to your computer and use it in GitHub Desktop.

Select an option

Save Thiago4532/2de37125a70b1bed4516b2d5a8d4c4ec to your computer and use it in GitHub Desktop.
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
int n;
map<long long, int> freq;
int32_t main() {
cin >> n;
long long s=0;
int ans = n - 1;
for(int i=1;i<=n;i++) {
int x;
cin >> x;
s += x;
freq[s]++;
ans = min(ans, n - freq[s]);
}
cout << ans << "\n";
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment