比赛 |
10.10.18noip模拟 |
评测结果 |
AAAAAAAAAA |
题目名称 |
罪犯问题B |
最终得分 |
100 |
用户昵称 |
Pom |
运行时间 |
0.000 s |
代码语言 |
C++ |
内存使用 |
0.00 MiB |
提交时间 |
2010-10-18 21:28:07 |
显示代码纯文本
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
using namespace std;
const int MAXN=1010;
const int MAXM=50050;
int n,m,k,i,j,c[MAXN],a[MAXN],b[MAXN],f[2][MAXM],ans1,ans2;
int main()
{
freopen("criminalb.in","r",stdin);
freopen("criminalb.out","w",stdout);
scanf("%d%d%d",&n,&m,&k);
for (i=1;i<=n;i++)
scanf("%d",&c[i]);
for (i=1;i<=m;i++)
{
scanf("%d",&j);
if (j>0) a[j]++;
else b[-j]++;
}
for (j=0;j<=k;j++)
f[0][j]=f[1][j]=-2000000000;
f[0][0]=0;
for (i=1;i<=n;i++)
for (j=0;j<=k;j++)
{
f[i%2][j]=-2000000000;
if (b[i]<=j) f[i%2][j]=f[(i+1)%2][j-b[i]]+c[i];
if (a[i]<=j) f[i%2][j]=max(f[i%2][j],f[(i+1)%2][j-a[i]]);
}
ans1=-2000000000;
for (i=0;i<=k;i++)
if (f[n%2][i]>ans1) ans1=f[n%2][i];
printf("%d\n",ans1);
for (j=0;j<=k;j++)
f[0][j]=f[1][j]=2000000000;
f[0][0]=0;
for (i=1;i<=n;i++)
for (j=0;j<=k;j++)
{
f[i%2][j]=2000000000;
if (b[i]<=j) f[i%2][j]=f[(i+1)%2][j-b[i]]+c[i];
if (a[i]<=j) f[i%2][j]=min(f[i%2][j],f[(i+1)%2][j-a[i]]);
}
ans2=2000000000;
for (i=0;i<=k;i++)
if (f[n%2][i]<ans2) ans2=f[n%2][i];
printf("%d\n",ans2);
return 0;
}