fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. int n;
  6. cin >> n;
  7. vector<int> v(n);
  8. int mx=0,zero=0,one=0,score=0;
  9. for (int i = 0; i < n; i++) {
  10. cin>>v[i];
  11. if(v[i]==0)++zero;
  12. else {
  13. ++one;
  14. ++score;
  15. }
  16. if(zero>one)
  17. mx=max(mx,zero-one);
  18. else {
  19. zero=0;
  20. one=zero;
  21. }
  22. }
  23. if(score+mx==score)cout<<score-1;
  24. else
  25. cout<<score+mx;
  26. }
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
32765