Untitled

 avatar
unknown
plain_text
a year ago
1.5 kB
9
Indexable
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
template<class T> using orderedset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
int dx[] = {0, 0, 1, -1, 1, 1, -1, -1};
int dy[] = {1, -1, 0, 0, 1, -1, 1, -1};
void File() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("errors.txt", "w", stderr);
#else

#endif
}
int main() {
    File();
    ll n, sz1, sz2, x, y;
    cin >> n >> sz1 >> sz2 >> x >> y;
    vector<ll> w(n), v(n);
    for (auto &e: w) cin >> e;
    for (auto &e: v) cin >> e;
    vector<vector<ll>> dp(sz1 + 1, vector<ll>(sz2 + 1, 0));
    ll ans = 0;
    for (int i = 0; i < n; ++i) {
        for (int id1 = sz1; id1 >= 0; --id1) {
            for (int id2 = sz2; id2 >= 0; --id2) {
                if (id1 + w[i] + x <= sz1)
                    dp[id1 + w[i] + x][id2] = max(dp[id1 + w[i] + x][id2], dp[id1][id2] + v[i]);
                if (id2 + w[i] + y <= sz2)
                    dp[id1][id2 + w[i] + y] = max(dp[id1][id2 + w[i] + y], dp[id1][id2] + v[i]);
            }
        }
    }
    for (int i = 0; i <= sz1; ++i)
        for (int j = 0; j <= sz2; ++j)
            ans = max(ans, dp[i][j]);
    cout << ans << "\n";
    return 0;
}
Editor is loading...
Leave a Comment