165122025-05-05 00:11:32algoproJobstown-i milliomoscpp17Accepted 100/10079ms1076 KiB
// UUID: 649532f1-117b-43cb-ae3a-912851575c11
#include <bits/stdc++.h>
using namespace std;

void solve(){
    int n, limit;
    cin >> n >> limit;

    vector<pair<long long, long long>> jobs(n);

    long long bv = 0, bw = 1;

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

        if (1.0 * jobs[i].second / jobs[i].first > 1.0 * bv / bw) {
            bv = jobs[i].second;
            bw = jobs[i].first;
        }
    }
        
    int db = 0;

    if (limit > 50000) {
        db = (limit - 46000) / bw;
    }

    limit -= bw * db;

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

    for (int i = 0; i <= limit; i++) {
        for (const auto& j : jobs) {
            if (j.first <= i) {
                dp[i] = max(dp[i], dp[i - j.first] + j.second);
            }

        }
    }

    cout << dp[limit] + db * bv;;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);


    solve();
    return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted1ms316 KiB
2Accepted1ms500 KiB
subtask225/25
3Accepted1ms380 KiB
4Accepted1ms316 KiB
5Accepted78ms820 KiB
6Accepted78ms820 KiB
7Accepted78ms820 KiB
8Accepted78ms820 KiB
9Accepted78ms820 KiB
10Accepted78ms820 KiB
11Accepted79ms684 KiB
12Accepted79ms820 KiB
13Accepted79ms1012 KiB
14Accepted1ms1076 KiB
subtask316/16
15Accepted72ms564 KiB
16Accepted71ms564 KiB
17Accepted72ms756 KiB
18Accepted1ms568 KiB
19Accepted71ms644 KiB
20Accepted71ms756 KiB
21Accepted71ms564 KiB
subtask459/59
22Accepted1ms316 KiB
23Accepted1ms316 KiB
24Accepted71ms564 KiB
25Accepted71ms564 KiB
26Accepted71ms564 KiB
27Accepted72ms564 KiB
28Accepted71ms564 KiB
29Accepted72ms756 KiB
30Accepted1ms564 KiB
31Accepted71ms564 KiB
32Accepted71ms564 KiB
33Accepted71ms756 KiB