#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
using ll = long long;
using pll = pair<ll, ll>;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
//___________________________
ll n, m, k; cin >> n >> m >> k;
vector<ll> p(n), b(m+1);
for (ll i = 0; i < n; i++) cin >> p[i];
for (ll i = 0; i <= m; i++) cin >> b[i];
vector<ll> dp(k+1, -(1e18));
dp[0] = 0;
for (ll i = 0; i < n; i++) {
ll cap = min(k, m-p[i]);
vector<ll> newdp(k+1, -(1e18));
vector<ll> gain(cap+1);
for (ll t = 0; t <= cap; t++) {
gain[t] = b[p[i]+t] - b[p[i]];
}
for (ll t = 0; t <= cap; t++) {
for (ll j = t; j <= k; j++) {
if (dp[j-t] != (ll)(-(1e18))) newdp[j] = max(newdp[j], dp[j-t]+gain[t]);
}
}
dp = newdp;
}
ll ans = 0;
for (ll i = 0; i < n; i++) ans += b[p[i]];
cout << dp[k]+ans << endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |