-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbookShop.cpp
More file actions
41 lines (31 loc) · 793 Bytes
/
bookShop.cpp
File metadata and controls
41 lines (31 loc) · 793 Bytes
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
// https://cses.fi/problemset/task/1158
#include <iostream>
#include <vector>
using namespace std;
int main ()
{
int n, x;
cin >> n >> x;
int prices[n];
int pages[n];
for (int i = 1; i <= n; ++i) cin >> prices[i];
for (int j = 1; j <= n; ++j) cin >> pages[j];
int matr[n+1][x+1];
for (int i = 0; i <= n; ++i) {
for (int j = 0; j <= n; ++j) {
matr[i][j] = -20;
}
}
for (int i = 0; i <= x; ++i) {
matr[0][i] = 0;
}
for (int i = 1; i <= n; ++i) {
for (int j = 0; j <= x; ++j) {
matr[i][j] = matr[i-1][j];
if (j >= prices[i]) {
matr[i][j] = max(matr[i][j], matr[i-1][j-prices[i]]+pages[i]);
}
}
}
cout << matr[n][x] << "\n";
}