Submission

Status:

[PPPPPPPPPPPPPPP]

Subtask/Task Score:

{100/100}

Score: 100

User: Ecir

Problemset: laracroft

Language: cpp

Time: 0.002 second

Submitted On: 2025-10-04 10:15:19

#include <bits/stdc++.h>
using namespace std;
using ll=long long int;
ll dp[2009];
ll arr[509];
ll w[509];
int main(){
    ios::sync_with_stdio(0);cin.tie(0);
    int n,lim;cin >> n >> lim;
    for(int i=1;i<=n;i++) cin >> arr[i];
    for(int i=1;i<=n;i++) cin >> w[i];
    for(int j=1;j<=n;j++){
        for(int i=lim;i>=1;i--){
            if(i-w[j]>=0) dp[i]=max(dp[i],dp[i-w[j]]+arr[j]);
        }
    }
    int mx=0,ans=0;
    for(int i=1;i<=lim;i++){
        if(mx<=dp[i] && dp[i]!=0){
            if(mx==dp[i]) ans=min(ans,i);
            else {
                mx=dp[i];
                ans=i;
            }
        }
    }
    cout << mx << ' ' << ans;
    // cout << '\n' << dp[1];


    return 0;
}