forked from tanvi1004/competitivesolutions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathknapsack1.cpp
More file actions
39 lines (32 loc) · 851 Bytes
/
knapsack1.cpp
File metadata and controls
39 lines (32 loc) · 851 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
/*
///////// ///// //// ////
// // // // // // //
////// // // // // //
// // /// // // //
//////// // // // //
*/
#include<bits/stdc++.h>
#include<assert.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;
#define Fast ios_base::sync_with_stdio(false); cin.tie(NULL);
#define fo(i,s,n) for(int i=s;i<n;i++)
#define pb(x) push_back(x);
#define mod 1000000007
int main()
{
Fast
ll n,w;
cin>>n>>w;
vector<ll>dp(w+1);
for(int i=1;i<=n;i++)
{
ll a, b;
cin>>a>>b;
for(int j=w;j>=a;j--)
dp[j]=max(dp[j-a]+b,dp[j]);
}
cout<<*max_element(dp.begin(),dp.end())<<endl;
return 0;
}