168412025-05-13 21:41:51algoproJobstown-i milliomoscpp17Wrong answer 0/10026ms756 KiB
// UUID: 28386f11-64c9-49b7-9976-2c44069416ea
#include <bits/stdc++.h>
using namespace std;



int main() {
    #define int long long
    int DP_LEN = 25000;
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,m;cin >> n >> m;
    vector<int> v(n);
    vector<int> t(n);
    for(int i = 0; i < n; i++)
    {
        cin >> t[i];
    }
    for(int i = 0; i < n; i++)
    {
        cin >> v[i];
    }

    int l = min(m, DP_LEN);
    vector<int> dp(l+1);
    dp[0] = 0;
    for(int i = 0; i < l; i++)
    {
        int max_num = 0;
        for(int j = 0; j < n; j++)
        {
            if(i + 1 - t[j] >= 0) max_num = max(max_num, dp[i + 1 -t[j]] + v[j]);
        }
        dp[i+1] = max_num;
    }
    int max_n = 0;
    for(int i = 0; i < l+1; i++)
    {
        max_n = max(dp[i], max_n);
    }
    pair<int, int> max_avg = {v[0], t[0]};
    for(int i = 1; i < n; i++)
    {
        if(v[i] * max_avg.second > t[i] * max_avg.first)
        {
            max_avg.first = v[i];
            max_avg.second = t[i];
        } 
    }   

    if(m <= DP_LEN)
    {
        cout << max_n << "\n";
    }
    else 
    {
        cout << max_n + ((m-DP_LEN) / max_avg.second) * max_avg.first;
    }
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted1ms508 KiB
2Accepted1ms316 KiB
subtask20/25
3Accepted1ms316 KiB
4Accepted1ms316 KiB
5Wrong answer26ms564 KiB
6Wrong answer26ms568 KiB
7Wrong answer25ms564 KiB
8Wrong answer26ms564 KiB
9Accepted26ms564 KiB
10Accepted26ms564 KiB
11Wrong answer26ms564 KiB
12Wrong answer26ms564 KiB
13Wrong answer26ms564 KiB
14Wrong answer1ms756 KiB
subtask30/16
15Wrong answer25ms564 KiB
16Wrong answer26ms568 KiB
17Wrong answer26ms756 KiB
18Wrong answer1ms564 KiB
19Accepted26ms564 KiB
20Accepted26ms564 KiB
21Accepted26ms564 KiB
subtask40/59
22Accepted1ms316 KiB
23Accepted1ms316 KiB
24Wrong answer26ms564 KiB
25Wrong answer26ms756 KiB
26Wrong answer26ms564 KiB
27Wrong answer26ms564 KiB
28Wrong answer26ms564 KiB
29Wrong answer26ms564 KiB
30Wrong answer1ms568 KiB
31Wrong answer26ms436 KiB
32Wrong answer26ms564 KiB
33Accepted26ms564 KiB