Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- int dp[1005][100005];
- int main()
- {
- int n;
- cin>>n;
- int price;
- cin>>price;
- vector<int>a;
- // price
- vector<int>b;
- //broj na strani
- for(int i=0; i<n; i++){
- int a1;
- cin>>a1;
- a.push_back(a1);
- }
- for(int i=0; i<n; i++){
- int b1;
- cin>>b1;
- b.push_back(b1);
- }
- for(int i=0; i<=n; i++){
- for(int j=0; j<=price; j++){
- dp[i][j]=-1;
- }
- }
- dp[0][0]=0;
- int result=0;
- for(int i=0; i<n; i++){
- for(int j=0; j<=price; j++){
- if(j+a[i]<=price){
- dp[i+1][j+a[i]]=max(dp[i+1][j+a[i]], dp[i][j]+b[i]);
- }
- dp[i+1][j]=max(dp[i+1][j], dp[i][j]);
- }
- }
- for(int i=0; i<=price; i++){
- result=max(result, dp[n][i]);
- }
- cout<<result;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement