Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int n,a[100001];
- int main()
- {
- cin>>n;
- int nrv1=0; /// Numarul de valori 1
- for(int i=1;i<=n;++i)
- cin>>a[i],nrv1+=a[i];
- for(int i=1;i<=n;++i) /// Calculam sumele partiale
- a[i]+=a[i-1];
- int nrmaxv1=a[nrv1]; /// numarul maxim de valori de 1 dintr-o secventa de lungime nrv1
- for(int i=nrv1+1;i<=n;++i)
- nrmaxv1=max(nrmaxv1,a[i]-a[i-nrv1]);
- cout<<nrv1-nrmaxv1;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement