Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- //#include <bits/stdc++.h>
- #include <fstream>
- #include <string>
- #include <set>
- #include <cstring>
- #define ll long long
- #define ld long double
- #define fi first
- #define se second
- #define mp make_pair
- #define pb push_back
- #define eb emplace_back
- #define all(x) (x).begin(), (x).end()
- #define INF 1e18
- #define eps 0.00001
- #define le length
- #define MOD 1000000007
- using namespace std;
- ll memo[2005][2005];
- int prices[1005];
- int pages[1005];
- int n;
- int x;
- int main() {
- // ifstream cin ("input.txt");
- cin >> n >> x;
- for(int i =0;i<n;i++){
- cin >> prices[i];
- }
- for(int i =0;i<n;i++){
- cin >> pages[i];
- }
- for(int i = 0; i < n; i++) {
- for(int j = 0; j <= x; j++) {
- memo[i][j] = -2e18;
- }
- }
- memo[0][x] = 0;
- for(int i =0; i < n; i++) {
- for(int j = x; j >= 0; j--) {
- memo[i + 1][j] = max(memo[i + 1][j], memo[i][j]);
- if(j - prices[i] >= 0) {
- memo[i + 1][j - prices[i]] = max(memo[i + 1][j - prices[i]], memo[i][j] + pages[i]);
- }
- }
- }
- ll result = 0;
- for(int i = 0; i <= x; i++) {
- result = max(result, memo[n][i]);
- }
- cout << result << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement