Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int main()
- {
- int n, *a, i, *f, sum = 0, max;
- scanf("%d",&n);
- a = (int *) malloc(n*sizeof(int));
- f = (int *) malloc(n*sizeof(int));
- f[0] = 0;
- for (i=1; i<=n; i++)
- {
- scanf("%d",&a[i]);
- if (a[i] == 1)
- {
- sum++;
- f[i] = f[i-1]-1;
- if (f[i]<0) f[i] = 0;
- }
- else f[i] = f[i-1]+1;
- }
- max = f[1];
- for (i=1; i<=n; i++)
- {
- //printf("%d ",f[i]);
- if (max < f[i]) max = f[i];
- }
- sum += max;
- printf("%d",sum);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement