-
Notifications
You must be signed in to change notification settings - Fork 2
/
e.cpp
62 lines (47 loc) · 900 Bytes
/
e.cpp
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int mod = 1e9 + 7;
ll int INF = 1e17;
ll int dp[105][100005];
int wgt[105];
int val[105];
ll int kil(int idx, int value)
{
if(value < 0)
return INF;
if(idx == 0)
{
if(value == 0)
return 0;
return INF;
}
if(dp[idx][value] != -1)
return dp[idx][value];
dp[idx][value] = INF;
dp[idx][value] = min(dp[idx][value], kil(idx-1, value));
dp[idx][value] = min(dp[idx][value], kil(idx-1, value - val[idx]) + wgt[idx]);
return dp[idx][value];
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
memset(dp, -1, sizeof dp);
int n, w;
cin>>n>>w;
for(int i=1;i<=n;i++)
cin>>wgt[i]>>val[i];
ll int res, ans=0;
for(int i=100000;i>=0;i--)
{
res = kil(n, i);
if(res <= w)
{
ans = i;
break;
}
}
cout<<ans<<endl;
return 0;
}