Submission #226887

# Submission time Handle Problem Language Result Execution time Memory
226887 2020-04-25T15:42:43 Z DavidDamian Sličice (COCI19_slicice) C++11
90 / 90
344 ms 1528 KB
#include <bits/stdc++.h>
using namespace std;
///Dynamic Programming
///Determine the maximum number of points when adding some extra images
int memo[505][505];
int A[505];
int B[1005];
int sum[505];
int points(int i,int k)
{
    if(i==0) return 0;
    if(k==0) return sum[i];
    if(memo[i][k]==-1){
        for(int j=0;j<=k;j++){
            memo[i][k]=max(memo[i][k],points(i-1,k-j)
                           +B[ A[i]+j ]);
        }
    }
    return memo[i][k];
}
int n,m,k;
int main()
{
    memset(memo,-1,sizeof(memo));
    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=m+1;i<=2*m+1;i++){
        B[i]=B[i-1];
    }
    for(int i=1;i<=n;i++){
        sum[i]=sum[i-1]+B[ A[i] ];
    }
    cout<<points(n,k)<<'\n';
    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 328 ms 1408 KB Output is correct
4 Correct 340 ms 1408 KB Output is correct
5 Correct 323 ms 1400 KB Output is correct
6 Correct 344 ms 1400 KB Output is correct
7 Correct 333 ms 1528 KB Output is correct
8 Correct 339 ms 1400 KB Output is correct
9 Correct 337 ms 1408 KB Output is correct
10 Correct 343 ms 1400 KB Output is correct