Submission #101978

# Submission time Handle Problem Language Result Execution time Memory
101978 2019-03-21T08:48:25 Z someone_aa Sličice (COCI19_slicice) C++17
90 / 90
89 ms 504 KB
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn = 510;
ll dp[2][maxn*maxn];
ll n, m, k;

ll p[maxn], b[maxn];

int main() {
    cin>>n>>m>>k;
    for(int i=1;i<=n;i++) {
        cin>>p[i];
    }

    for(int i=0;i<=m;i++) {
        cin>>b[i];
    }

    // dp[i][k] -> prefix of size i with k more pictures

    ll result = 0LL;
    for(int i=1;i<=n;i++) {

        int ci = i % 2;
        int pi = (i-1) % 2;

        for(int j=0;j<=k;j++) {
            dp[ci][j] = dp[pi][j] + b[p[i]];
            for(int c=0;c+p[i]<=m;c++) {
                if(j - c >= 0)
                    dp[ci][j] = max(dp[ci][j], dp[pi][j-c] + b[c+p[i]]);
            }
            result = max(result, dp[ci][j]);
        }
    }
    cout<<result<<"\n";
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 72 ms 384 KB Output is correct
4 Correct 72 ms 384 KB Output is correct
5 Correct 89 ms 384 KB Output is correct
6 Correct 70 ms 388 KB Output is correct
7 Correct 67 ms 384 KB Output is correct
8 Correct 79 ms 504 KB Output is correct
9 Correct 87 ms 392 KB Output is correct
10 Correct 89 ms 504 KB Output is correct