Description
Input Format
7 2
2 1 1 2 2 1 1
<br />
Output Format
6
<br />
Hint
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=1010, M=35;
LL f[N][M], a[N];
int main(){
int n, m; scanf("%d%d", &n, &m);
for(int i=1; i<=n; i++){
scanf("%d", &a[i]);
}
memset(f, 0, sizeof(f));
for(int i=0; i<=m; i++) f[0][i]=0;
for(int i=1; i<=n; i++){
for(int j=0; j<=m; j++){
f[i][j]=f[i-1][j];
if(j!=0) f[i][j]=max(f[i][j], f[i-1][j-1]);
if(a[i]==(j%2+1)) f[i][j]++;
}
}
LL ans=0;
for(int i=0; i<=m; i++)
ans=max(ans, f[n][i]);
printf("%lld\n", ans);
return 0;
}