stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#include <bits/stdc++.h>



using namespace std;





typedef long long ll;



const int MAX = 1e5+5;

ll dp[MAX+MAX];



int n , W;







int main()

{



    ios_base::sync_with_stdio(0);cin.tie(0);

    cin>>n>>W;



    for( int j = 0 ; j < MAX+MAX ; j++ )

        dp[j] = LONG_LONG_MAX;





    dp[0] = 0;

    ll ans = 0;

    for( int i = 1; i <= n ; i++ ) {





        ll w , v;

        cin>>w>>v;



        for( int j = MAX ; j >= 0 ; j-- ) {



            if( dp[j] != LONG_LONG_MAX ) {



                dp[j+v] = min( dp[j+v] , dp[j]+w );

                if( dp[j+v] <= W )

                ans = max( ans , j+v );



            }



        }



    }



    cout<<ans<<"\n";

}


// Optimized solution to the same problem (faster):
#include<cstdio>

#include<cstring>

#include<iostream>

#include<algorithm>

using namespace std;

typedef long long ll;

ll dp[100005];

int main(){

	int n,W;

	int w[105],v[105];

	scanf("%d%d",&n,&W);

	int sum = 0;

	for(int i = 1;i <= n;i++){

		scanf("%d%d",&w[i],&v[i]);

		sum += v[i];

	}

	for(int i = 1;i <= sum;i++) dp[i] = 0x3f3f3f3f;

	for(int i = 1;i <= n;i++){

		for(int j = sum;j >= v[i];j--){

		//	dp[j] = 0x3f3f3f3f;

			dp[j] = min(dp[j],dp[j - v[i]] + w[i]);//--

			//cout << j  << ' ' << dp[j] << endl;

		}

	}

	/*这道题为啥从1开始：

	因为如果dp[0] = 0x3f3f3f3f;

	dp[j] = min(0x3f3f3f3f,0x3f3f3f3f + w[i])

	就不用解释了

	只要dp[0] = 0;

	那么dp[v[i]] = min(0x3f3f3f3f,0 + w[i]);



	极大注意：尽量在循环外面进行初始化

	*/

	ll ans = 0;

	for(int i = sum;i >= 0;i--){

		if(dp[i] <= W){

			ans = i;

			break;

		}

	}

	printf("%lld\n",ans);

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
// Author : Syed Mujtaba

// Seek knowledge from the Cradle to the Grave !!

// https://www.linkedin.com/in/syed-mujtaba-064a5016a 



#include <bits/stdc++.h>

using namespace std;

#define int     long long

#define fast_io ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

signed main()

{

	fast_io

	int n, w;

	cin >> n >> w;

	vector < int > wt(n), val(n);

	int dp[n + 1][100008] = {0};



	for(int i = 0; i < n; i++)

		cin >> wt[i] >> val[i];

	for(int i = 0; i <= 100000; i++) // base case

	{

		if(i == 0)

			dp[1][0] = 0;

		else if(i == val[0] && wt[0] <= w)

			dp[1][i] = wt[0];

		else

			dp[1][i] = 1e18;

	}

	for(int i = 2; i <= n; i++) // tabulation

	{

		for(int j = 0; j <= 100000; j++)

		{

			dp[i][j] = 1e18;

			dp[i][j] = dp[i - 1][j];

			if(j - val[i - 1] >= 0)

				dp[i][j] = min(dp[i][j], dp[i - 1][j - val[i - 1]] + wt[i - 1]);

		}	

	}

	int ans;

	for(int i = 0; i <= 100000; i++)

	{

		if(dp[n][i] <= w)

			ans = i;

	}

	cout << ans << endl;

}

// Optimized solution to the same problem (faster):
#include<cstdio>

#include<cstring>

#include<iostream>

#include<algorithm>

using namespace std;

typedef long long ll;

ll dp[100005];

int main(){

	int n,W;

	int w[105],v[105];

	scanf("%d%d",&n,&W);

	int sum = 0;

	for(int i = 1;i <= n;i++){

		scanf("%d%d",&w[i],&v[i]);

		sum += v[i];

	}

	for(int i = 1;i <= sum;i++) dp[i] = 0x3f3f3f3f;

	for(int i = 1;i <= n;i++){

		for(int j = sum;j >= v[i];j--){

		//	dp[j] = 0x3f3f3f3f;

			dp[j] = min(dp[j],dp[j - v[i]] + w[i]);//--

			//cout << j  << ' ' << dp[j] << endl;

		}

	}

	/*这道题为啥从1开始：

	因为如果dp[0] = 0x3f3f3f3f;

	dp[j] = min(0x3f3f3f3f,0x3f3f3f3f + w[i])

	就不用解释了

	只要dp[0] = 0;

	那么dp[v[i]] = min(0x3f3f3f3f,0 + w[i]);



	极大注意：尽量在循环外面进行初始化

	*/

	ll ans = 0;

	for(int i = sum;i >= 0;i--){

		if(dp[i] <= W){

			ans = i;

			break;

		}

	}

	printf("%lld\n",ans);

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

#include<cstdio>

#include<algorithm>



using namespace std;



const int INF = 1e9 + 7;

const int MAX_V = 1e3 + 1;

const int MAX_N = 101;

int max_V;

int n,W;

int w[MAX_N],v[MAX_N];

int dp[MAX_N+1][MAX_N * MAX_V+1];



//dp[i+1][j]:从前i件物品中得到价值为j时的最小重量,不存在就是INF

//转移的话,就看第i类是要还是不要

int solve(){

    fill(dp[0], dp[0] + MAX_V * MAX_N + 1, INF);//没有物品可拿,自然是INF

    dp[0][0] = 0;

    for (int i = 0; i < n; i++){

        for (int j = 0; j <= max_V * n; j++){

            if(j<v[i]){

                dp[i + 1][j] = dp[i][j];//装不下

            }else{

                dp[i + 1][j] = min(dp[i][j], dp[i ][j - v[i]] + w[i]);

            }

        }

    }

    int res = 0;

    for (int i = 0;i<=max_V*n; i++){

        

        if(dp[n][i]<=W){

            res = i;

            //cout << dp[n][i] << " ";

        }

        

    }

    return res;

}



int main(){

    scanf("%d%d", &n, &W);

    for (int i = 0; i < n; i++){

        scanf("%d %d", &w[i], &v[i]);

        max_V = max(max_V, v[i]);

    }

    cout << solve() << endl;

    return 0;

}

// Optimized solution to the same problem (faster):
#include<cstdio>

#include<cstring>

#include<iostream>

#include<algorithm>

using namespace std;

typedef long long ll;

ll dp[100005];

int main(){

	int n,W;

	int w[105],v[105];

	scanf("%d%d",&n,&W);

	int sum = 0;

	for(int i = 1;i <= n;i++){

		scanf("%d%d",&w[i],&v[i]);

		sum += v[i];

	}

	for(int i = 1;i <= sum;i++) dp[i] = 0x3f3f3f3f;

	for(int i = 1;i <= n;i++){

		for(int j = sum;j >= v[i];j--){

		//	dp[j] = 0x3f3f3f3f;

			dp[j] = min(dp[j],dp[j - v[i]] + w[i]);//--

			//cout << j  << ' ' << dp[j] << endl;

		}

	}

	/*这道题为啥从1开始：

	因为如果dp[0] = 0x3f3f3f3f;

	dp[j] = min(0x3f3f3f3f,0x3f3f3f3f + w[i])

	就不用解释了

	只要dp[0] = 0;

	那么dp[v[i]] = min(0x3f3f3f3f,0 + w[i]);



	极大注意：尽量在循环外面进行初始化

	*/

	ll ans = 0;

	for(int i = sum;i >= 0;i--){

		if(dp[i] <= W){

			ans = i;

			break;

		}

	}

	printf("%lld\n",ans);

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;



//int from[1009];



int main()

{ 

  ll dp[100009];

  for(int i=1;i<=100005;i++)

    dp[i] = 10000000000000ll;

  ll w[109];

  int v[109];

  dp[0]= 0;

  int n;

  ll cap;

  ll sum = 0;

  cin >> n >> cap; 

  for(int i=0;i<n;i++){

    cin >> w[i] >> v[i];

    sum = sum + v[i]; 

  }

  //cout << sum << endl;

  for(int i=0;i<n;i++){



      int current = sum - v[i];

      for(int j = current; j>=0;j--){

        int index = j + v[i];

          //cout << j << " " << dp[index] << " " << dp[j]+w[i] << endl;

        dp[index] = min(dp[index],dp[j]+w[i]);

      

      }

      

      //cout << endl;

    

  }



  int ans = 0;

  for(int i=0;i<=sum;i++){

    if(dp[i]<=cap)

      ans = max(i,ans);

  }

  cout << ans << endl;



}

// Optimized solution to the same problem (faster):
#include<cstdio>

#include<cstring>

#include<iostream>

#include<algorithm>

using namespace std;

typedef long long ll;

ll dp[100005];

int main(){

	int n,W;

	int w[105],v[105];

	scanf("%d%d",&n,&W);

	int sum = 0;

	for(int i = 1;i <= n;i++){

		scanf("%d%d",&w[i],&v[i]);

		sum += v[i];

	}

	for(int i = 1;i <= sum;i++) dp[i] = 0x3f3f3f3f;

	for(int i = 1;i <= n;i++){

		for(int j = sum;j >= v[i];j--){

		//	dp[j] = 0x3f3f3f3f;

			dp[j] = min(dp[j],dp[j - v[i]] + w[i]);//--

			//cout << j  << ' ' << dp[j] << endl;

		}

	}

	/*这道题为啥从1开始：

	因为如果dp[0] = 0x3f3f3f3f;

	dp[j] = min(0x3f3f3f3f,0x3f3f3f3f + w[i])

	就不用解释了

	只要dp[0] = 0;

	那么dp[v[i]] = min(0x3f3f3f3f,0 + w[i]);



	极大注意：尽量在循环外面进行初始化

	*/

	ll ans = 0;

	for(int i = sum;i >= 0;i--){

		if(dp[i] <= W){

			ans = i;

			break;

		}

	}

	printf("%lld\n",ans);

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

#include<cstring>

#include<vector>

using namespace std;

const int maxn = 1e5 + 10;

long long w[maxn];

long long v[maxn];

long long dp[maxn];

int main(){

	int n,V;

	long long ans = 0;

	scanf("%d%d",&n,&V);

    for(int i = 1;i<=n;i++) 

		scanf("%lld%lld",&v[i],&w[i]);

    memset(dp,0x3f,sizeof(dp));

    dp[0] = 0;

    for(int i = 1;i<=n;i++)

    {

        for(int j = 100000;j>=w[i];j--)

            dp[j] = min(dp[j],dp[j-w[i]]+v[i]);

    }

    for(int i = 1;i<=1e5;i++) 

	if(dp[i]<=V) 

		ans = max(ans,(long long)i);

    printf("%lld\n",ans);

	return 0;

}


// Optimized solution to the same problem (faster):
#include<cstdio>

#include<cstring>

#include<iostream>

#include<algorithm>

using namespace std;

typedef long long ll;

ll dp[100005];

int main(){

	int n,W;

	int w[105],v[105];

	scanf("%d%d",&n,&W);

	int sum = 0;

	for(int i = 1;i <= n;i++){

		scanf("%d%d",&w[i],&v[i]);

		sum += v[i];

	}

	for(int i = 1;i <= sum;i++) dp[i] = 0x3f3f3f3f;

	for(int i = 1;i <= n;i++){

		for(int j = sum;j >= v[i];j--){

		//	dp[j] = 0x3f3f3f3f;

			dp[j] = min(dp[j],dp[j - v[i]] + w[i]);//--

			//cout << j  << ' ' << dp[j] << endl;

		}

	}

	/*这道题为啥从1开始：

	因为如果dp[0] = 0x3f3f3f3f;

	dp[j] = min(0x3f3f3f3f,0x3f3f3f3f + w[i])

	就不用解释了

	只要dp[0] = 0;

	那么dp[v[i]] = min(0x3f3f3f3f,0 + w[i]);



	极大注意：尽量在循环外面进行初始化

	*/

	ll ans = 0;

	for(int i = sum;i >= 0;i--){

		if(dp[i] <= W){

			ans = i;

			break;

		}

	}

	printf("%lld\n",ans);

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

#include<stdio.h>

#include<algorithm>

#include<cstring>

#include<queue>

#include<vector>

#define ll long long

#define pi acos(-1.0)

#define inf 0x3f3f3f3f

using namespace std;

const int maxn = 1e6+5;

int v[maxn];

ll dp[maxn], w[maxn];



int main(){

	memset(dp, 0x3f, sizeof(dp));

	int n, W; cin >> n >> W;

	int sum = 0;

	for(int i = 1; i <= n; i++){

		cin >> w[i] >> v[i];

		sum += v[i];

	}

	dp[0] = 0;

	for(int i = 1; i <= n; i++){

		for(int j = sum; j >= v[i]; j--)

			dp[j] = min(dp[j], dp[j-v[i]] + w[i]);

	}

	for(int i = sum; i >= 0; i--){

		if(dp[i] <= W){

			cout << i << endl;

			break;

		}

	}

}

// Optimized solution to the same problem (faster):
#include<cstdio>

#include<cstring>

#include<iostream>

#include<algorithm>

using namespace std;

typedef long long ll;

ll dp[100005];

int main(){

	int n,W;

	int w[105],v[105];

	scanf("%d%d",&n,&W);

	int sum = 0;

	for(int i = 1;i <= n;i++){

		scanf("%d%d",&w[i],&v[i]);

		sum += v[i];

	}

	for(int i = 1;i <= sum;i++) dp[i] = 0x3f3f3f3f;

	for(int i = 1;i <= n;i++){

		for(int j = sum;j >= v[i];j--){

		//	dp[j] = 0x3f3f3f3f;

			dp[j] = min(dp[j],dp[j - v[i]] + w[i]);//--

			//cout << j  << ' ' << dp[j] << endl;

		}

	}

	/*这道题为啥从1开始：

	因为如果dp[0] = 0x3f3f3f3f;

	dp[j] = min(0x3f3f3f3f,0x3f3f3f3f + w[i])

	就不用解释了

	只要dp[0] = 0;

	那么dp[v[i]] = min(0x3f3f3f3f,0 + w[i]);



	极大注意：尽量在循环外面进行初始化

	*/

	ll ans = 0;

	for(int i = sum;i >= 0;i--){

		if(dp[i] <= W){

			ans = i;

			break;

		}

	}

	printf("%lld\n",ans);

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

#define eps 1e-3

#define pi acos(-1.0)

#define inf 0x3f

#define INF 0x3f3f3f3f

#define pb push_back

#define debug1 cout<<"&&";

#define debug2 cout<<"**";

#define ms(a, x) memset(a, x, sizeof(a))

#define for0(i, n) for(int i = 0; i < n; ++i)

#define for1(i, n) for(int i = 1; i <= n; ++i)

using namespace std;

typedef double db;

typedef long long ll;

typedef unsigned long long ull;

typedef pair<int, int> pii;

typedef pair<long long, int> pli;

typedef pair<long long, long long> pll;

const int mod = 1e9 + 7;

const int N = 1e5+10;

const int M = 1e6+10;

inline int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

inline ll Pow(ll a, ll b) { ll ans = 1; for( ; b; b >>= 1) { if(b&1) ans = ans * a % mod; a = a * a % mod;} return ans;}

inline ll Mul ( ll a, ll b)  { ll lf = a * ( b >> 25ll ) % mod * ( 1LL << 25 ) % mod; ll rg = a * ( b & ( ( 1ll << 25 ) - 1 ) ) % mod; return ( lf + rg ) % mod;}

//==================================================================================================================================================================//



ll n, W, dp[N];

int ans;



int main() {

   scanf("%lld %lld", &n, &W);

   ms(dp, inf); dp[0] = 0;

   for1(i, n) {

      ll w, v;

      scanf("%lld %lld", &w, &v);

      for(int j = 100000; j >= v; --j) {

         dp[j] = min(dp[j], dp[j-v] + w);

      }

   }

   for1(i, 100000) if(dp[i] <= W) ans = i;

   printf("%d\n", ans);

   return 0;

}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define REPT(x, l, r) for(int x = l; x <=r; ++x)

#define REP(x, n) for(int x = 0; x <n; ++x)

int n, w;

int main(){

    cin>>n>>w;

    int arr[n+1];

    int arr2[n+1];

    int sum = 0;

    REPT(x, 1, n){

        cin>>arr[x]>>arr2[x];

        sum += arr2[x];

    }



    int dp[n+1][sum+1] = {};



    dp[0][0] = 0;



    REPT(x, 0, n){

        REPT(y, 1, sum){

            if(x == 0){

                dp[x][y] = w+1;

            }else{

                if(y < arr2[x]){

                    dp[x][y] = dp[x-1][y];

                }else{

                    dp[x][y] = min(dp[x-1][y], arr[x] + dp[x-1][y-arr2[x]]);

                }

            }

        }

    }

    int maxa = 0;

    for(int x = 1; x<= sum;x++){

        if(dp[n][x] <= w)

            maxa = x;

    }

    cout<<maxa<<endl;





}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

#define MOD 1000000007

#define ll long long

#define li long

#define pb push_back

#define mem(arr,x) memset(arr,x,sizeof(arr))



ll n,W;

ll w[101],v[101];

ll dp[101][100010];

bool vis[101][100010];

ll totalV=0;



ll minWeight(ll end, ll Val)

{

  if(Val<=0)

  return 0;

  if(end==0)

  return INT_MAX;

  if(vis[end][Val])

  return dp[end][Val];

  vis[end][Val]=1;

  // if(v[end-1]>Val)

  // return dp[end][Val]=minWeight(end-1,Val);

  // else

  return dp[end][Val]=min(w[end-1]+minWeight(end-1,Val-v[end-1]), minWeight(end-1,Val));

}



int main() 

{

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    ll i,j;

    cin>>n>>W;

    for(i=0;i<n;i++)

    {

      cin>>w[i]>>v[i];

      totalV+=v[i];

    }

    mem(vis,0);

    for(i=0;i<=n;i++)

      for(j=0;j<=totalV;j++)

        dp[i][j]=INT_MAX;



    for(i=totalV;i>=1;i--)

    {

      if(minWeight(n,i)<=W)

      break;

    }

    cout<<i;

    return 0;

}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

using namespace std;

#define MOD 1000000007

#define ll long long

#define li long

#define pb push_back

#define mem(arr,x) memset(arr,x,sizeof(arr))



ll n,W;

ll w[101],v[101];

ll dp[101][100010];

ll totalV=0;



ll minWeight(ll end, ll Val)

{

  if(Val<=0)

  return 0;

  if(end==0)

  // return 1000000010;

  return INT_MAX;

  // 2147483647

  if(dp[end][Val]!=1000000010)

  return dp[end][Val];

  if(v[end-1]>Val)

  return dp[end][Val]=minWeight(end-1,Val);

  else

  return dp[end][Val]=min(w[end-1]+minWeight(end-1,Val-v[end-1]), minWeight(end-1,Val));

}



ll bottomUp()

{

  ll i,j;

  for(i=0;i<=n;i++)

  {

    for(j=0;j<=totalV;j++)

    {

      if(j==0)

      dp[i][j]=0;

      else if(i==0)

      dp[i][j]=INT_MAX;

      else if(j>=v[i-1])

      dp[i][j]=min(w[i-1]+dp[i-1][j-v[i-1]], dp[i-1][j]);

      else 

      dp[i][j]=dp[i-1][j];

    }

  }

  for(j=totalV;j>=1;j--)

  {

    if(dp[n][j]<=W)

    break;

  }

  return j;

}



int main() 

{

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    ll i,j;

    cin>>n>>W;

    for(i=0;i<n;i++)

    {

      cin>>w[i]>>v[i];

      totalV+=v[i];

    }



    for(i=0;i<=n;i++)

      for(j=0;j<=totalV;j++)

        dp[i][j]=1000000010;



    // for(i=totalV;i>=1;i--)

    // {

    //   if(minWeight(n,i)<=W)

    //   break;

    // }

    // cout<<i;

    cout<<bottomUp();

    return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <vector>

#include <algorithm>

#include <numeric>

#include <cmath>

#include <set>

#include <tuple>

#include <functional>

#include <map>

#include <unordered_map>

#include <queue>

#include <tuple>



using namespace std;



#define endl '\n'



using ull = unsigned long int;

using ll = long long;



int main() {

  ios_base::sync_with_stdio(false);

  cin.tie(nullptr);

  const int precision = 13;

  cout.precision(precision);

  cout.setf(ios_base::fixed);



  int n, W; cin >> n >> W;

  vector<ll> dp(1e5+10, W+1);



  dp[0] = 0;

  for (int i = 0; i < n; ++i) {

    ll w, v; cin >>  w >> v;

    for (int j = 1e5; j - v >= 0; --j) {

      dp[j] = min(dp[j], dp[j-v] + w);

    }

  }



  int ans = 0;

  for (int i = 1; i <= 1e5; ++i) {

    if (dp[i] <= W) {

      ans = max(ans, i);

    }

  }

  cout << ans << endl;



  return 0;

}


// Optimized solution to the same problem (faster):
#include<cstdio>

#include<cmath>

#include<cstring>

#include<cstdlib>

#include<algorithm>

#include<iostream>

#include<queue>

#include<string>

#include<map>

#include<set>

#include<stack>

#include<vector>

#define ll long long

#define mt(a) memset(a,0,sizeof(a))

#define MAXI 2000000000

#define PAI pair<int,int>



using namespace std;



ll  f[200009],w[200009],v[200009];

int main()

{

	int n, m,vv=0;

	scanf("%d%d", &n, &m);

	for (int i = 1; i <= n; i++)

	{

		scanf("%lld%lld", &w[i], &v[i]);

		vv += v[i];

	}

	for (int i = 1; i <= vv; i++)

		f[i] = MAXI;

	for (int i = 1; i <= n; i++)

	{

		for (int c = vv; c >= v[i]; c--)

		{

			f[c] = min(f[c], f[c - v[i]] + w[i]);

		}

	}

	ll maxx = -MAXI;

	for (int i = 0; i <= vv; i++)

		if (f[i] <= m) maxx = i;

	printf("%lld\n", maxx);

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
/**

 *  Author : Coda

 *  Title : OSU!

 *  Date : 2019-08-20

 */

#include <bits/stdc++.h>

using namespace std ;



typedef long long ll ;

typedef unsigned long long ull ;

typedef double DB ;

const long long mod = 1e9+7 ;

const double pi = acos(-1) ;

#define PB push_back

#define MP make_pair

#define lb lower_bound

#define ub upper_bound

#define fs first

#define sd second

#define pii pair<int,int>

#define INF 0x3f3f3f3f

#define LLINF 0x3f3f3f3f3f3f3f3f

#define debug(x) cout << #x << " = " << x << endl

#define debug2(x,y) cout << #x << " = " << x << ' ' << #y << " = " << y << endl

#define debug3(x,y,z) cout << #x << " = " << x << ' ' << #y << " = " << y << ' ' << #z << " = " << z << endl

//#pragma comment(linker,"/STACK:10240000,10240000")

//#include <random>

//mt19937 rand_(time(0));

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

ll qpow(ll a,ll b,ll c){ll t=1;while(b){if(b&1)t=t*a%c;a=a*a%c;b>>=1;}return t;}

ll inv(ll x){return qpow(x,mod-2,mod);}

int test = 1 ;



const int maxn = 5 + 3e5 ;

const int maxm = 5 + 1e6 ;

// Write the variables here



int N,W ;

ll v[maxn],w[maxn] ;

ll dp[maxn] ;



//#define TEST

int main(){

#ifdef TEST

    freopen("in.txt","r",stdin) ;

#endif

    while(test--){

        // code begins

        scanf("%d%d",&N,&W) ;



        ll sum = 0 ;

        for(int i=1 ; i<=N ; i++){

            scanf("%lld%lld",&w[i],&v[i]) ;

        }

        for(int i=1 ; i<=100000 ; i++){

            dp[i] = LLINF ;

        }

        dp[0] = 0;

        ll ans = 0 ;

        for(int i=1 ; i<=N ; i++){

            for(int j=100000 ; j>=v[i] ; j--){

                dp[j] = min(dp[j],dp[j-v[i]]+w[i]);

            }

        }

        for(int i=1 ; i<=100000 ; i++){

            if(dp[i]<=W) ans = max(ans,i*1ll) ;

        }

        printf("%lld\n",ans) ;



    }

#ifdef TEST

    cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;

#endif

    return 0 ;

}


// Optimized solution to the same problem (faster):
#include<cstdio>

#include<cmath>

#include<cstring>

#include<cstdlib>

#include<algorithm>

#include<iostream>

#include<queue>

#include<string>

#include<map>

#include<set>

#include<stack>

#include<vector>

#define ll long long

#define mt(a) memset(a,0,sizeof(a))

#define MAXI 2000000000

#define PAI pair<int,int>



using namespace std;



ll  f[200009],w[200009],v[200009];

int main()

{

	int n, m,vv=0;

	scanf("%d%d", &n, &m);

	for (int i = 1; i <= n; i++)

	{

		scanf("%lld%lld", &w[i], &v[i]);

		vv += v[i];

	}

	for (int i = 1; i <= vv; i++)

		f[i] = MAXI;

	for (int i = 1; i <= n; i++)

	{

		for (int c = vv; c >= v[i]; c--)

		{

			f[c] = min(f[c], f[c - v[i]] + w[i]);

		}

	}

	ll maxx = -MAXI;

	for (int i = 0; i <= vv; i++)

		if (f[i] <= m) maxx = i;

	printf("%lld\n", maxx);

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

#include<cstring>

#include<cstdio>

using namespace std;

typedef long long ll;

const int maxn = 1000010;

const int inf = 0x3f3f3f3f;

ll dp[maxn];

ll n, W;

ll v[maxn];

ll w[maxn];

inline ll max(ll x, ll y) {

	return x > y ? x : y;

}

inline ll min(ll x, ll y) {

	return x < y ? x : y;

}

int main() {

	memset(dp, 0x3f, sizeof(dp));

	ios::sync_with_stdio(false);

	cin.tie(0);

	cout.tie(0);

	cin >> n >> W;

	for (int i = 1; i <= n; i++)

		cin >> w[i] >> v[i];

	ll ans = 0ll;

	dp[0] = 0;

	for (int i = 1; i <= n; i++){

		for (int j = 1e5; j >= v[i]; --j){

			dp[j] = min(dp[j], dp[j - v[i]] + w[i]);

			if (dp[j] <= W) ans = max(ans, (ll)(j));

		}

	}

	cout << ans;

	return 0;

}

// Optimized solution to the same problem (faster):
#include<cstdio>

#include<cmath>

#include<cstring>

#include<cstdlib>

#include<algorithm>

#include<iostream>

#include<queue>

#include<string>

#include<map>

#include<set>

#include<stack>

#include<vector>

#define ll long long

#define mt(a) memset(a,0,sizeof(a))

#define MAXI 2000000000

#define PAI pair<int,int>



using namespace std;



ll  f[200009],w[200009],v[200009];

int main()

{

	int n, m,vv=0;

	scanf("%d%d", &n, &m);

	for (int i = 1; i <= n; i++)

	{

		scanf("%lld%lld", &w[i], &v[i]);

		vv += v[i];

	}

	for (int i = 1; i <= vv; i++)

		f[i] = MAXI;

	for (int i = 1; i <= n; i++)

	{

		for (int c = vv; c >= v[i]; c--)

		{

			f[c] = min(f[c], f[c - v[i]] + w[i]);

		}

	}

	ll maxx = -MAXI;

	for (int i = 0; i <= vv; i++)

		if (f[i] <= m) maxx = i;

	printf("%lld\n", maxx);

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
/*

    Mbak Rose Dong

*/

#include<bits/stdc++.h>

using namespace std;

long long int weight[105], value[105];

long long int dp[100100];

int main()

{

    int n, i, j, k, curr, m, ans;

    int tc;

    int w;

    scanf("%d %d",&n,&w);

    for(i=1;i<=n;i++)

    {

        scanf("%lld %lld",&weight[i], &value[i]);

    }

    for(i=1;i<=100000;i++)

        dp[i] = 1e15;

    dp[0] = 0;

    for(i=1;i<=n;i++)

    {

        for(j=100000-value[i];j>=0;j--)

        {

            dp[j+value[i]] = min(dp[j+value[i]], dp[j] + weight[i]);

        }

    }

    for(i=100000;i>=0;i--)

    {

        if(dp[i] <= w)

        {

            printf("%d\n",i);

            return 0;

        }

    }

    return 0;

}


// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

using namespace std;

#define MAXN 100

#define MAXV 1000

#define MAXW 1000000000

#define INF 10000000000000LL





int w[MAXN], v[MAXN];

int n,C;

long long dp[MAXN*MAXV+1];

int totalV;



int main() {

	int i,j;

	scanf("%d %d",&n, &C);	

	for (totalV=i=0; i<n;i++) {

		scanf("%d %d",&w[i],&v[i]);

		totalV += v[i];

	}

	dp[0]=0;

	for (i=1; i<=totalV;i++) {

		dp[i]=INF;

	}



	for (i=0; i<n; i++) {

		for (j=totalV; j>=v[i]; j--) {

			dp[j]=min(dp[j], dp[j-v[i]]+w[i]);

		}

	}

	for (i=totalV; i>=0;i--) {

		if (dp[i]<= C) break;

	}

	printf("%d\n",i);

	return 0;

}

// Fastest known solution for this problem: