显示代码纯文本
#include<iostream>
#include<cstdio>
using namespace std;
int y[50001];
int jl1[50001],jl2[50001],cnt1=0,cnt2=0;
int n;
int main()
{
freopen("diningb.in","r",stdin);
freopen("diningb.out","w",stdout);
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
scanf("%d",&y[i]);
if(y[i]==1)
cnt1++;
else
cnt2++;
}
for(int i=1;i<=n;i++)
{
jl1[i]=jl1[i-1];
if(y[i]==2)
jl1[i]++; //记录当前点前全部改成1,要改的次数
}
for(int i=n;i>=1;i--)
{
jl2[i]=jl2[i+1];
if(y[i]==1)
jl2[i]++; //记录当前点后全部改成2,要改的次数
}
int minn=min(cnt1,cnt2);
for(int i=1;i<=n;i++)
minn=min(minn,jl1[i]+jl2[i+1]);
cout<<minn;
return 0;
}