-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path12865.cpp
More file actions
32 lines (32 loc) · 719 Bytes
/
12865.cpp
File metadata and controls
32 lines (32 loc) · 719 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
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
vector<int> cost;
vector<pair<int,int>> stuff;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int T,M,x,y;
cin>>T>>M;
cost.assign(M+1,0);
for(int i=0;i<T;i++)
{
cin>>x>>y;
stuff.push_back({x,y});
}
for(int i=0;i<stuff.size();i++)
{
int weight=stuff[i].first;
int value=stuff[i].second;
for(int j=M;j>=0;j--)
if(j==0 || cost[j]!=0)
if(weight + j <=M)
cost[j+weight]=max(cost[j]+value,cost[j+weight]);
}
int ans=0;
for(int i=1;i<=M;i++)
ans=max(ans,cost[i]);
cout<<ans;
}