Language: C++

#include<bits/stdc++.h>

typedef long long ll;
using namespace std;
const ll INF = 1e12L + 5;

int main()
{
    ll n,w,sum_val=0,ans=0;//Code By: pratibha_899 (Pratibha Shrivastav)
 
/********   All Required Header Files ********/
#include<bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
 
using namespace std;
 
//All the Loops and defines required
typedef long long int ll;
#define FOR(i, j, k, in) for (ll i=j ; i<k ; i+=in)
#define RFOR(i, j, k, in) for (ll i=j ; i>=k ; i-=in)
#define REP(i, j) FOR(i, 0, j, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
#define MP make_pair
#define PB push_back
#define ff first
#define ss second
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define INFI 1000000000000
 
//All the declarations using typedef
 
typedef pair<ll, ll> PII;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<ll, ll> MPII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
typedef long int l;
typedef unsigned long int ul;
typedef unsigned long long int  ull;
 
ll knapsack(ll n,ll w, ll weights[], ll values[],ll sum_values){
	
    ll dp[n+1][sum_values+1];
	
    for(ll i=0;i<=n;i++){
		for(ll j=0;j<=sum_values;j++)
			dp[i][j]=INFI;
	}
	
  for(ll i=0;i<n+1;i++)
		dp[i][0]=0;
	
    for(ll i=1;i<n+1;i++){
		for(ll j=sum_values;j>=0;j--){
				dp[i][j]=min(dp[i-1][j],dp[i-1][j-values[i]]+weights[i]);
		}
	}
  
	ll max_value;
	for(ll i=0;i<sum_values;i++){
        if(dp[n][i]<=w)
            max_value=i;
	}
	return max_value;
}
 
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n,w;
	cin>>n>>w;
	ll weights[n+1];
	ll values[n+1];
	for(ll i=1;i<=n;i++)
		cin>>weights[i]>>values[i];
	ll sum_values=0;
	for(ll i=1;i<=n;i++)
		sum_values+=values[i];
	ll res = knapsack(n,w,weights,values,sum_values);
	cout<<res;
	return 0;
}
    scanf("%lld %lld",&n,&w);
    ll val[n],wgt[n];
    
    for(int i=0;i<n;i++)
    {
        scanf("%lld %lld",wgt+i,val+i);
        sum_val += val[i];
    }

    vector <ll> dp(sum_val+1,INF);
    dp[0] = 0;

    for(int i=0;i<n;i++)
    {
        for(int j=sum_val-val[i];j>=0;j--)
        {
            dp[j+val[i]] = min(dp[j+val[i]],dp[j]+wgt[i]);
        }
    }
    for(int i=0;i<=sum_val;i++)
    {
        if(dp[i]<=w)
            ans = max(ans, (ll)i);
    }
    cout<<ans<<"\n";
}

Compiler output:
a.cc: In function 'int main()':
a.cc:74:64: error: a function-definition is not allowed here before '{' token
   74 | ll knapsack(ll n,ll w, ll weights[], ll values[],ll sum_values){
      |                                                                ^
a.cc:100:9: warning: empty parentheses were disambiguated as a function declaration [-Wvexing-parse]
  100 | int main()
      |         ^~
a.cc:100:9: note: remove parentheses to default-initialize a variable
  100 | int main()
      |         ^~
      |         --
a.cc:100:9: note: or replace parentheses with braces to value-initialize a variable
a.cc:101:1: error: a function-definition is not allowed here before '{' token
  101 | {
      | ^