-
Notifications
You must be signed in to change notification settings - Fork 0
/
E.cpp
85 lines (80 loc) · 1.77 KB
/
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
********************
Author : Sahil Kundu
********************
*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define mod 1000000007
#define pb(i) push_back(i)
#define f first
#define s second
#define mk(l,r) make_pair(l,r)
#define vi vector<int>
#define vl vector<ll>
#define vch vector<char>
#define all(vc) vc.begin(),vc.end()
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ms(i,j) memset(i,j,sizeof i)
#define w(t) while(t--)
#define len(s) s.length()
#define rep(i,n) for(ll i=0;i<(n);++i)
#define repa(i,n) for(ll i=n;i>=0;i--)
#define yes cout<<"Yes\n"
#define no cout<<"No\n"
#define PI 3.14159265358979323846
#define fastIO ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)
const ll MAX=1e5+5;
const ll INF=2e18;
#define INPUT_OUTPUT {\
freopen("input.txt","r",stdin);\
freopen("output.txt","w",stdout);\
}
// logical code of program starts here.
void solve()
{
int n,w;
cin>>n>>w;
ll mx=1010*n+2;
ll dp[mx];
ll val[n+1],wt[n+1];
rep(i,mx)dp[i]=INF;
rep(i,n+1)cin>>wt[i+1]>>val[i+1];
dp[0]=0;
rep(i,n+1)
{
if(i==0)continue;
repa(x,mx-1)
{
if(val[i]>x)break;
dp[x]=min(dp[x],dp[x-val[i]]+wt[i]);
}
}
repa(i,mx-1)
if(dp[i]<=w)
{
cout<<i<<endl;
break;
}
}
// mian function
int main()
{
//INPUT_OUTPUT;//file handling
fastIO;// fast input output
clock_t start, end;
start = clock();
int t;
t=1;
//cin>>t;
w(t) solve();
end = clock();
double time_taken = double(end - start)/double(CLOCKS_PER_SEC);
clog << "Time taken by program is : " << fixed
<< time_taken << setprecision(5);
clog << " sec " << endl;
return 0;
}