Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define x first
- #define y second
- #define pb push_back
- using namespace std;
- typedef long long ll;
- const int N = 100005;
- int n, pre[N], cnt = 0, ans = 2e9;
- int main() {
- ios_base::sync_with_stdio(false);
- cin.tie(0);
- cin >> n;
- pre[0] = 0;
- for (int i = 1; i <= n; i++) {
- int x;
- cin >> x;
- cnt += x;
- pre[i] = pre[i - 1] + x;
- }
- for (int i = 1; i <= (n - cnt + 1); i++) {
- ans = min(ans, cnt - pre[i + cnt - 1] + pre[i - 1]);
- }
- cout << ans << '\n';
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment