forked from namishkhanna/hacktoberfest2020
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BookShop.cpp
54 lines (45 loc) · 1.17 KB
/
BookShop.cpp
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
49
50
51
52
53
54
#include <iostream>
#include <vector>
#include <string>
#include <climits>
#include <set>
#include <algorithm>
using namespace std;
#define ll long long int
#define OJ \
freopen("input.txt", "r", stdin); \
freopen("output.txt", "w", stdout);
#define FIO \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
int main()
{
OJ;
int n, maxBooks;
cin >> n >> maxBooks;
int* prices = new int[n];
int* pages = new int[n];
for(int i=0; i<n; i++){
cin >> prices[i];
}
for(int i=0; i<n; i++){
cin >> pages[i];
}
vector<vector<int>> dp(n+1, vector<int>(maxBooks+1, 0));
for(int i=1; i<=n; i++){
for(int j= 0; j <=maxBooks; j++){
dp[i][j] = dp[i-1][j];
int left = j-prices[i-1];
if(left>=0){
dp[i][j] = max(dp[i][j], dp[i-1][left]+pages[i-1]);
}
}
}
for(int i=0; i<=n; i++){
for(int j=0; j<=maxBooks; j++){
cout << dp[i][j] << " ";
}
cout << endl;
}
}