fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int n,A[100100];
  5. int fun()
  6. {
  7. int ans=0;
  8. int count=0;
  9. for(int i=1;i<=n;i++)
  10. {
  11. if(A[i]==1)
  12. {
  13. count++;
  14. ans=max(ans,count);
  15. }
  16. else
  17. {
  18. count=0;
  19. }
  20. }
  21. return ans;
  22. }
  23.  
  24. int main() {
  25. cin>>n;
  26. int ans=0;
  27. for(int i=1;i<=n;i++)
  28. {
  29. cin>>A[i];
  30. }
  31. for(int i=1;i<=n;i++)
  32. {
  33. for(int j=1;j<=n;j++)
  34. {
  35. swap(A[i], A[j]);
  36. ans=max(ans, fun());
  37. swap(A[i], A[j]);
  38.  
  39. }
  40. }
  41. cout<<ans<<endl;
  42.  
  43. return 0;
  44. }
Success #stdin #stdout 0s 15624KB
stdin
5
1 1 1 0 1
stdout
4