163632025-04-28 20:54:04algoproJobstown-i milliomoscpp17Runtime error 25/100246ms262144 KiB
// UUID: 392b4f42-e475-40c9-97c1-cf7f3486ad90
#include <bits/stdc++.h>
using namespace std;

//O(m) space, still fails :(

void solve() {
    int n, m;
    cin >> n >> m;
    vector<pair<long long, int>> tasks(n);

    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        
        tasks[i].second = a;
    }

    for (int i = 0; i < n; i++) {
        long long b;
        cin >> b;
        
        tasks[i].first = b;
    }

    vector<long long> dp(m + 1, 0);

    for (int curr = 1; curr <= m; curr++) {
        for (const auto& task : tasks) {
            if (task.second <= curr) {
                dp[curr] = max(dp[curr], dp[curr - task.second] + task.first);
            }
        }
    }

    cout << dp[m];
    return;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
    //cin >> t;

    while (t--) {
        solve();
    }

    return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted1ms316 KiB
2Accepted1ms316 KiB
subtask225/25
3Accepted1ms316 KiB
4Accepted1ms316 KiB
5Accepted76ms820 KiB
6Accepted76ms820 KiB
7Accepted76ms820 KiB
8Accepted76ms824 KiB
9Accepted76ms820 KiB
10Accepted76ms836 KiB
11Accepted76ms820 KiB
12Accepted76ms820 KiB
13Accepted76ms820 KiB
14Accepted1ms820 KiB
subtask30/16
15Runtime error202ms262144 KiB
16Runtime error200ms262144 KiB
17Runtime error244ms262144 KiB
18Runtime error244ms262144 KiB
19Runtime error202ms262144 KiB
20Runtime error201ms262144 KiB
21Runtime error241ms262144 KiB
subtask40/59
22Accepted1ms316 KiB
23Accepted1ms316 KiB
24Runtime error246ms262144 KiB
25Runtime error197ms262144 KiB
26Runtime error196ms262144 KiB
27Runtime error241ms262144 KiB
28Runtime error202ms262144 KiB
29Runtime error246ms262144 KiB
30Runtime error245ms262144 KiB
31Runtime error204ms262144 KiB
32Runtime error201ms262144 KiB
33Runtime error241ms262144 KiB