传送门:https://www.luogu.org/problemnew/show/P2837#sub
#include<cstdio>
#include<algorithm>
using namespace std;
inline int read()
{
static char ch;
while((ch = getchar()) < '0' || ch > '9');
int ret = ch - 48;
while((ch = getchar()) >= '0' && ch <= '9')
ret = ret * 10 + ch - 48;
return ret;
}
int n,a[30010],ans;
struct node
{
int one,two;
}t[30010];
int main()
{
n = read();
for(int i = 1;i <= n;i++)
{
a[i] = read();
if(a[i] == 1)
{
t[i].one = t[i-1].one + 1;
t[i].two = t[i-1].two;
}
else
{
t[i].two = t[i-1].two + 1;
t[i].one = t[i-1].one;
}
}
ans = min(t[n].one,t[n].two);
for(int i = 1;i <= n;i++)
ans = min(ans,t[n].one - t[i].one + t[i].two);
printf("%d",ans);
return 0;
}