给你 n,m 第一行有n个,第二行m个;
n 行 就只有0,1;接下来就是有m个数字,代表有多个连续的0或者1
6 3
1 0 0 1 0 1
1 3 2转成 011100这样的最小操作次数
/*#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
bool vis[111], mp[111][111];
const int inf = (int)1e9 * 2;
int main()
{
int p, n, i, j;
while (cin >> p >> n)
{
for (i = 0; i <= p; i++)
{
vis[i] = 0;
for(j = 0; j <= n; j++)
{
mp[i][j] = inf;
}
}
for (i = 0; i < n; i++)
{
int x, y, c;
scanf("%d%d%d", &x, &y, &c);
mp[x][y] = mp[y][x] = min(mp[x][y], c);
}
}
return 0;
}*/
#include<iostream>
#include<cstdio>
#include<numeric>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
int a[111], b[111],n;
const int inf = (int)1e9 + 10;
int solve()
{
if (accumulate(a, a + n, 0) != accumulate(b, b + n, 0))
return inf;
int tm[111] = { 0 },i,j;
memcpy(tm, b, sizeof(b));
int ans = 0;
for (i = 0; i < n; i++)
{
if (a[i] == tm[i])
continue;
for (j = i + 1; j < n; j++)
{
if (tm[j] == a[i])
{
while (j > i)
{
swap(tm[j], tm[j - 1]);
j--;
ans++;
}
break;
}
}
}
return ans;
}
int main()
{
int m, i, j;
while (cin>>n>>m)
{
for (i = 0; i < n; i++) scanf("%d", a + i);
int id = 0,v=0;
while (m--)
{
int x; scanf("%d", &x);
while (x--) b[id++] = v;
v ^= 1;
}
int s1=solve();
for (i = 0; i < n; i++)
b[i] ^= 1;
int s2 = solve();
cout << min(s1, s2) << endl;
}
return 0;
}