AlexNeagu11

Untitled

Feb 23rd, 2024
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define x first
  3. #define y second
  4. #define pb push_back
  5. using namespace std;
  6. typedef long long ll;
  7. const int N = 100005;
  8. int n, pre[N], cnt = 0, ans = 2e9;
  9. int main() {
  10. ios_base::sync_with_stdio(false);
  11. cin.tie(0);
  12. cin >> n;
  13. pre[0] = 0;
  14. for (int i = 1; i <= n; i++) {
  15. int x;
  16. cin >> x;
  17. cnt += x;
  18. pre[i] = pre[i - 1] + x;
  19. }
  20. for (int i = 1; i <= (n - cnt + 1); i++) {
  21. ans = min(ans, cnt - pre[i + cnt - 1] + pre[i - 1]);
  22. }
  23. cout << ans << '\n';
  24. return 0;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment