#include <bits/stdc++.h>
using namespace std;
///Dynamic Programming with answer
///Determine the maximum number of points when adding some extra images
int memo[505][505];
int p[505][505];
int A[505];
int B[1005];
int sum[505];
int extra[505];
int n,m,K;
void answer(int i,int k)
{
if(i==0 || k==0) return;
extra[i]=p[i][k];
answer(i-1,k-extra[i]);
}
int main()
{
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>n>>m>>K;
for(int i=1;i<=n;i++){
cin>>A[i];
}
for(int i=0;i<=m;i++){
cin>>B[i];
}
for(int i=1;i<=n;i++){
sum[i]=sum[i-1]+B[ A[i] ];
}
for(int i=m+1;i<=2*m+1;i++){
B[i]=B[i-1];
}
for(int i=1;i<=n;i++){
memo[i%2][0]=sum[i];
for(int k=1;k<=K;k++){
for(int j=0;j<=k;j++){
int points=memo[(i-1)%2][k-j]+B[ A[i]+j ];
if(points>memo[i%2][k]){
memo[i%2][k]=points;
p[i][k]=j;
}
}
}
}
cout<<memo[n%2][K]<<'\n';
//answer(n,K);
//for(int i=1;i<=n;i++){
// cout<<extra[i]<<" ";
//}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
1408 KB |
Output is correct |
2 |
Correct |
5 ms |
1408 KB |
Output is correct |
3 |
Correct |
65 ms |
1528 KB |
Output is correct |
4 |
Correct |
60 ms |
1276 KB |
Output is correct |
5 |
Correct |
60 ms |
1400 KB |
Output is correct |
6 |
Correct |
62 ms |
1272 KB |
Output is correct |
7 |
Correct |
61 ms |
1272 KB |
Output is correct |
8 |
Correct |
61 ms |
1272 KB |
Output is correct |
9 |
Correct |
61 ms |
1272 KB |
Output is correct |
10 |
Correct |
59 ms |
1272 KB |
Output is correct |