range queries and one graph
This commit is contained in:
24
CSES - CSES Problem Set/Dynamic_Programming/Book_Shop.cpp
Normal file
24
CSES - CSES Problem Set/Dynamic_Programming/Book_Shop.cpp
Normal file
@@ -0,0 +1,24 @@
|
||||
// Book Shop
|
||||
|
||||
#include<bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main() {
|
||||
int n, x; cin >> n >> x;
|
||||
vector<int> price(n);
|
||||
vector<int> pages(n);
|
||||
for (auto &e: price) cin >> e;
|
||||
for (auto &e: pages) cin >> e;
|
||||
|
||||
int dp[1000001];
|
||||
for (int i{}; i < n; i++) {
|
||||
for (int j = x; j >= price[i]; j--) {
|
||||
dp[j] = max(dp[j], dp[j - price[i]] + pages[i]);
|
||||
}
|
||||
}
|
||||
|
||||
cout << dp[x] << endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user