
我的代码:
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
// #define x first
// #define y second
// typedef long long LL;
// typedef std::pair<int,int> PII;
const int N=1e5+10;
// const int inf=1e8+10;
// const int err=-1;
// const double eps=1e-10;
const int M=1e2+10;
const int L=2+10;
using namespace std;
int n,k;
int w[N];
int cnt=0;
int f[N][M][L];
int main()
{
#ifndef ONLINE_JUDGE
freopen("monopoly-4.in","r",stdin);
freopen("monopoly-4.out","w",stdout);
#endif
scanf("%d%d",&n,&k);
for(int i=1;i<=n;i++)
{
scanf("%d",&w[i]);
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=k;j++)
{
f[i][j][0]=max(f[i-1][j][0],f[i-1][j][1]+w[i]);
f[i][j][1]=max(f[i-1][j][1],f[i-1][j-1][0]-w[i]);
}
}
printf("%d\n",f[n][k][0]);
return 0;
}
提交后显示RE,求原因