Submission

Status:

[PPPPPPPPPPPPPPP]

Subtask/Task Score:

{100/100}

Score: 100

User: meme_boi2

Problemset: laracroft

Language: cpp

Time: 0.003 second

Submitted On: 2026-03-18 15:31:08

#include <bits/stdc++.h>
using namespace std;
vector<int> dp(2002,0);
int32_t main(){
    cin.tie(nullptr)->sync_with_stdio(0);
    int n, k;
    cin >>  n >> k;
  //  memset(dp,200,sizeof(dp));
    vector<int> price(n), weight(n);
    for(auto &x: weight) cin >> x;
    for(auto &x : price) cin >> x;
    dp[0] = 0;
    
    for(int i = 0; i < n; i++){
        for(int j = k; j - price[i] >= 0; j--){
            dp[j] = max(dp[j],dp[j-price[i]] + weight[i]);
        }
    }
    int ans = -2e9, idx = -1;
    for(int j = 0; j <= k; j++){
       // cout << dp[j] << ' ';
        if(dp[j] > ans){
            ans = dp[j];
            idx = j;
        }
    }
    cout << dp[idx] << ' ' << idx;
}

/*
cd "c:\Users\RICOH-NB110\Desktop\Computer Programing\gchan\" ; if ($?) { g++ c2_knb64_laracroft.cpp -o c2_knb64_laracroft } ; if ($?) { .\c2_knb64_laracroft }

6 10
20 5 10 40 15 25
1 2 3 8 7 4
*/