-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbook_shop.cpp
More file actions
48 lines (46 loc) · 1.03 KB
/
Copy pathbook_shop.cpp
File metadata and controls
48 lines (46 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <bits/stdc++.h>
using namespace std;
#define inf (int)(1e9+7)
#define sz(s) (int)s.size()
#define all(v) v.begin(),v.end()
#define fill0(dp) memset(dp,0,sizeof(dp))
#define fill(dp) memset(dp,-1,sizeof(dp))
#define input(v) for (auto &i : v) cin >> i;
#define print(v) for (auto &j : v) cout << j << " "; cout << "\n";
void solve()
{
int n,x;
cin>>n>>x;
vector<int>h(n),s(n);
input(h);
input(s);
vector<vector<int>>dp(n,vector<int>(x+1,0));
for(int j=1;j<=x;j++)
{
if(j>=h[0]) dp[0][j]=s[0];
}
for(int i=1;i<n;i++)
{
for(int j=1;j<=x;j++)
{
if(j-h[i]>=0)
{
dp[i][j] = max(dp[i-1][j],dp[i-1][j-h[i]]+s[i]);
}
else
{
dp[i][j] = dp[i-1][j];
}
}
}
cout<<dp[n-1][x];
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);cout.tie(nullptr);
int testcases=1;
//cin>>testcases;
while(testcases--) solve();
return 0;
}