We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent c35857a commit 0df1916Copy full SHA for 0df1916
book-shop.cpp
@@ -0,0 +1,27 @@
1
+#include <bits/stdc++.h>
2
+using namespace std;
3
+typedef long long ll;
4
+#define vi vector<int>
5
+#define vvi vector<vector<int>>
6
+int n,x;
7
+int rec(int cap,vi& price, vi& pages) {
8
+ // dp[i][j] = max pages we can buy with i items and j rupees
9
+ vvi dp(n+1,vi(cap+1));
10
+ for (int i = 1; i <= n; ++i) {
11
+ for (int j = 0; j <= cap; ++j) {
12
+ if(price[i - 1] > j) dp[i][j] = dp[i-1][j];
13
+ else dp[i][j] = max(dp[i-1][j-price[i-1]] + pages[i-1],dp[i-1][j]);
14
+ }
15
16
+ return dp[n][x];
17
+}
18
+void solve() {
19
+ cin >> n >> x;// x = capacity;
20
+ vi price(n); for (int i = 0; i < n; ++i) cin >> price[i];
21
+ vi pages(n); for (int i = 0; i < n; ++i) cin >> pages[i];
22
+ cout << rec(x, price, pages) << endl;
23
+
24
25
+int32_t main() {
26
+ solve();
27
0 commit comments