criyle/codenet-compile-errors huggingface dataset:
Language: C++

#include <bits/stdc++.h>
using namespace std;

int t[1002][102];

int knapsackdpTab(int val[], int wt[], int w, int n) // Tabulation
{
    for (int i = 0; i < w + 1; i++)
    {
        for (int j = 0; j < n + 1; j++)
        {
            if (i == 0 || j == 0)
                t[i][j] = 0;
        }
    }

    for (int i = 1; i < w + 1; i++)
    {
        for (int j = 1; j < n + 1; j++)
        {
            if (wt[j - 1] <= i)
                t[i][j] = max(val[j - 1] + t[i - wt[j - 1]][j - 1], t[i][j - 1]);
            else
                t[i][j] = t[i][j - 1];
        }
    }

    return t[w][n];
}

int main()
{
    memset(t, -1, sizeof(t));
    int n, w;
    cin >> n >> w;
    int wt[n];
    int val[n];
    for(int i=0; i<n; i++)
        cin >> wt[i] >> val[i];


    cout << knapsackdpMemo(val, wt, w, n);
}


Compiler output:
a.cc: In function 'int main()':
a.cc:42:13: error: 'knapsackdpMemo' was not declared in this scope; did you mean 'knapsackdpTab'?
   42 |     cout << knapsackdpMemo(val, wt, w, n);
      |             ^~~~~~~~~~~~~~
      |             knapsackdpTab
Language: C++

#ifndef ONLINE_JUDGE
#include "debug.cpp"
#endif

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define ar array


void solve() {
    int n, S;
    cin >> n >> S;
    vector<int> w(n), v(n);
    for(int i = 0; i < n; ++i) cin >> w[i] >> v[i];
    vector<vector<int>> dp(n,vector<int>(S+1,0));
    for(int i = 0;i < n; ++i){
        for(int j = 0;j <= S; ++j){
            if(i > 0) {
                if (w[i] > j) dp[i][j] = dp[i - 1][j];
                else dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w[i]] + v[i]);
            }else{
                if(w[i] <= j) dp[i][j] = v[i];
            }
        }
    }
    debug(dp);
    cout << dp[n-1][S] << "\n";
    //cout << *max_element(dp[n-1].begin(),dp[n-1].end()) << "\n";
}

int32_t main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);

    int TC = 1;
    while (TC--)
        solve();

    return 0;
}



Compiler output:
a.cc:2:10: fatal error: debug.cpp: No such file or directory
    2 | #include "debug.cpp"
      |          ^~~~~~~~~~~
compilation terminated.
Language: C++

 #include<bits/stdc++.h>
using namespace std;
int ans(int v[],int w[],int wt,int n)
{
    if(n==0||wt==0)
    return 0;
    if(w[n-1]<=wt)
    return max(v[n-1]+ans(v,w,wt-w[n-1],n-1),ans(v,w,wt,n-1));
    else
    return ans(v,w,wt,n-1);
}
int main()
{
    int n,wt,p;
    cin>>n>>wt;
   long int v[n],w[n];
    for(int i=0;i<n;i++)
    cin>>w[i]>>v[i];
    p=ans(v,w,wt,n);
    cout<<p<<endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:19:11: error: cannot convert 'long int*' to 'int*'
   19 |     p=ans(v,w,wt,n);
      |           ^
      |           |
      |           long int*
a.cc:3:13: note:   initializing argument 1 of 'int ans(int*, int*, int, int)'
    3 | int ans(int v[],int w[],int wt,int n)
      |         ~~~~^~~
Language: C++

#include<iostream>
#include<algorithm>
#include<cstring>
#define ll long long
using namespace std;
ll v[103],w[103];
ll ks(ll n,ll W){
  ll dp[W+1];
  memset(dp,0,sizeof(dp));  
  for(int i=0;i<n;i++) 
    for(int j=W;j>=w[i];j--)
      dp[j]=max(dp[j],dp[j-w[i]]+v[i]);
  return dp[W];
}


int main(){
  ll n,w;
  cin>>n>>w;
  for(int i=0;i<n;i++)
     cin>>w[i]>>v[i];
  cout<<ks(n,w)<<endl;
 return 0; 
}


Compiler output:
a.cc: In function 'int main()':
a.cc:21:12: error: invalid types 'long long int[int]' for array subscript
   21 |      cin>>w[i]>>v[i];
      |            ^
Language: C++

#include<iostream>
#include<algorithm>
#include<cstring>
#define ll long long
using namespace std;
int v[103],w[103];
int ks(int n,int W){
  ll dp[W+1];
  memset(dp,0,sizeof(dp));  
  for(int i=0;i<n;i++) 
    for(int j=W;j>=w[i];j--)
      dp[j]=max(dp[j],dp[j-w[i]]+v[i]);
  return dp[W];
}


int main(){
  int n,w;
  cin>>n>>w;
  for(int i=0;i<n;i++)
     cin>>w[i]>>v[i];
  cout<<ks(n,w)<<endl;
 return 0; 
}

Compiler output:
a.cc: In function 'int main()':
a.cc:21:12: error: invalid types 'int[int]' for array subscript
   21 |      cin>>w[i]>>v[i];
      |            ^
Language: C++

#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;

const int LIM = 105;
int n, w;
int q[LIM];
long long ans = 0, sum[100005], v[LIM];


int main() {
    cin >> n >> w;

    for(int i = 1; i <= n; ++i) 
        cin >> q[i] >> v[i];
    

    vector <int> s;

    for (int j = 1; j <= n; ++j) 
        vector<pair<int,long long>> modificari;
        ans = max(ans, v[j]);

        int lg = s.size();

        if (sum[q[j]] == 0)  //daca nu exista o multime cu a j greutate, o punem in sirul de multimi
            s.push_back(q[j]);

        for (int k = 0; k < lg; ++k) {

            if (s[k] + q[j] <= w){ //daca greutatea se incadreaza in W

                if (sum[s[k] + q[j]] == 0) // daca nu am greutatea multime + element nou in sir
                    s.push_back(s[k] + q[j]);

                modificari.push_back(make_pair(s[k] + q[j], sum[s[k]] + v[j]));

                ans = max(ans, sum[s[k]] + v[j]);
            }
        }
        sum[q[j]] = max(sum[q[j]], v[j]);

        for (size_t i = 0; i < modificari.size(); ++i) 
            sum[modificari[i].first] = max(sum[modificari[i].first], modificari[i].second);
    }


    cout << ans;
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:25:26: error: 'j' was not declared in this scope
   25 |         ans = max(ans, v[j]);
      |                          ^
a.cc:39:17: error: 'modificari' was not declared in this scope
   39 |                 modificari.push_back(make_pair(s[k] + q[j], sum[s[k]] + v[j]));
      |                 ^~~~~~~~~~
a.cc:46:32: error: 'modificari' was not declared in this scope
   46 |         for (size_t i = 0; i < modificari.size(); ++i)
      |                                ^~~~~~~~~~
a.cc: At global scope:
a.cc:51:5: error: 'cout' does not name a type
   51 |     cout << ans;
      |     ^~~~
a.cc:52:5: error: expected unqualified-id before 'return'
   52 |     return 0;
      |     ^~~~~~
a.cc:53:1: error: expected declaration before '}' token
   53 | }
      | ^
Language: C++

#include <bits/stdc++.h>
#include <iostream>

using namespace std;

//State
//dp[i][j]: The maximum value of items we can take when there are 
//	only first j items available and knapsack can carry atmost i kg's 

//Initialization
//if W[0] <= i then dp[i][0]=V[0] else dp[i][1]=0

//Transitions: Either we put the j-th item in knapsack or we exclude it
//dp[i][j] = max(dp[i-W[j]][j-1], dp[i][j-1])

//Order of evaluation
//Row wise or Column Wise

//Answer
//dp[W][N-1]
using ll = long long 

ll dp[100005];
int W[100005];
int V[100005];

int main(){
	cin >> N >> W;
	for(int i=0; i<N; i++){
		cin >> W[i] >> V[i];
	}
	//Intializing fist row
	for(int j=0; j<N; j++){
		dp[0][i] = 0;
	}
	//Intializing the first column
	for(int i=0; i<=W; i++){
		if(i>=V[0]) dp[i][0] = W[0];
		else dp[i][0] = 0;
	}
	//Evaluation Order and Transitions
	for(int i=1; i<=W; i++){
		for(int j=0; j<N; j++){
			if(i-W[j]>=0){
				dp[i][j] = max(dp[i-W[j]][j-1]+V[j], dp[i][j-1]);
			}
			else{
				dp[i][j] = dp[i][j-1];
			}
		}
	}
	cout << dp[W][N-1] << endl;
}

Compiler output:
a.cc:21:21: error: expected ';' before 'll'
   21 | using ll = long long
      |                     ^
      |                     ;
   22 | 
   23 | ll dp[100005];
      | ~~                   
a.cc: In function 'int main()':
a.cc:28:16: error: 'N' was not declared in this scope
   28 |         cin >> N >> W;
      |                ^
a.cc:34:17: error: 'dp' was not declared in this scope; did you mean 'dup'?
   34 |                 dp[0][i] = 0;
      |                 ^~
      |                 dup
a.cc:34:23: error: 'i' was not declared in this scope
   34 |                 dp[0][i] = 0;
      |                       ^
a.cc:37:23: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
   37 |         for(int i=0; i<=W; i++){
      |                      ~^~~
a.cc:38:29: error: 'dp' was not declared in this scope; did you mean 'dup'?
   38 |                 if(i>=V[0]) dp[i][0] = W[0];
      |                             ^~
      |                             dup
a.cc:39:22: error: 'dp' was not declared in this scope; did you mean 'dup'?
   39 |                 else dp[i][0] = 0;
      |                      ^~
      |                      dup
a.cc:42:23: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
   42 |         for(int i=1; i<=W; i++){
      |                      ~^~~
a.cc:45:33: error: 'dp' was not declared in this scope; did you mean 'dup'?
   45 |                                 dp[i][j] = max(dp[i-W[j]][j-1]+V[j], dp[i][j-1]);
      |                                 ^~
      |                                 dup
a.cc:48:33: error: 'dp' was not declared in this scope; did you mean 'dup'?
   48 |                                 dp[i][j] = dp[i][j-1];
      |                                 ^~
      |                                 dup
a.cc:52:17: error: 'dp' was not declared in this scope; did you mean 'dup'?
   52 |         cout << dp[W][N-1] << endl;
      |                 ^~
      |                 dup
Language: C++

 #include  <bits/stdc++.h> 
using namespace std;
 
#define ll long long
#define ar array
#define pii pair<int,int>
#define mp make_pair
 
const ll INF = 1e18;
const ll mod = 1000000007;
const int mxn=10e6;

void solve(){
	int N,W;
	cin >> N >> W;
    vector<int> w(N), v(N);
    for(int i = 0; i < N; i++) {
        cin>>w[i]>>v[i];
    }
    int dp[N+2][W+2]
    for(int i = 0; i < N; i++) {
        for(int j = 0; j <= W; j++) {
            if(i == 0) { if(j >= w[i]) dp[i][j] = v[i];}
            else if(j - w[i] >= 0) dp[i][j] = max(v[i] + dp[i-1][j-w[i]], dp[i-1][j]);
            else dp[i][j] = dp[i-1][j];
        }
    }
	cout<<dp[N-1][W];
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
	// int t;
	// cin>>t;
	// while(t--)
		solve();
	return 0;
}

Compiler output:
a.cc: In function 'void solve()':
a.cc:21:5: error: expected initializer before 'for'
   21 |     for(int i = 0; i < N; i++) {
      |     ^~~
a.cc:21:20: error: 'i' was not declared in this scope
   21 |     for(int i = 0; i < N; i++) {
      |                    ^
a.cc:28:15: error: 'dp' was not declared in this scope; did you mean 'dup'?
   28 |         cout<<dp[N-1][W];
      |               ^~
      |               dup
Language: C++

 #include  <bits/stdc++.h> 
using namespace std;
 
#define ll long long
#define ar array
#define pii pair<int,int>
#define mp make_pair
 
const ll INF = 1e18;
const ll mod = 1000000007;
const int mxn=10e6;

void solve(){
	int N,W;
	cin >> N >> W;
    vector<int> w(N), v(N);
    for(int i = 0; i < N; i++) {
        cin>>w[i]>>v[i];
    }

    for(int i = 0; i < N; i++) {
        for(int j = 0; j <= W; j++) {
            if(i == 0) { if(j >= w[i]) dp[i][j] = v[i];}
            else if(j - w[i] >= 0) dp[i][j] = max(v[i] + dp[i-1][j-w[i]], dp[i-1][j]);
            else dp[i][j] = dp[i-1][j];
        }
    }
	cout<<dp[N-1][W];
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
	// int t;
	// cin>>t;
	// while(t--)
		solve();
	return 0;
}

Compiler output:
a.cc: In function 'void solve()':
a.cc:23:40: error: 'dp' was not declared in this scope; did you mean 'dup'?
   23 |             if(i == 0) { if(j >= w[i]) dp[i][j] = v[i];}
      |                                        ^~
      |                                        dup
a.cc:24:36: error: 'dp' was not declared in this scope; did you mean 'dup'?
   24 |             else if(j - w[i] >= 0) dp[i][j] = max(v[i] + dp[i-1][j-w[i]], dp[i-1][j]);
      |                                    ^~
      |                                    dup
a.cc:25:18: error: 'dp' was not declared in this scope; did you mean 'dup'?
   25 |             else dp[i][j] = dp[i-1][j];
      |                  ^~
      |                  dup
a.cc:28:15: error: 'dp' was not declared in this scope; did you mean 'dup'?
   28 |         cout<<dp[N-1][W];
      |               ^~
      |               dup
Language: C++

#include <bits/stdc++.h>
using namespace std;
vector<int> dp[]
int rec(vector<int>& W, vector<int>& V, int n, int w){
	if(n < 1 or w == 0){
		return 0;
	}
	if(w-W[n-1] >= 0){
		return max(V[n-1]+rec(W, V, n-1, w-W[n-1]), rec(W, V, n-1, w));
	}
	else{
			return rec(W, V, n-1, w);
	}
}
int main() {
	int n, w;
	cin >> n >> w;
	vector<int> W(n), V(n);
	for(int i = 0; i < n; i++){
		cin >> W[i];
		cin >> V[i];
	}
	cout << rec(W, V, n, w) << "\n";
	return 0;
}

Compiler output:
a.cc:4:1: error: expected initializer before 'int'
    4 | int rec(vector<int>& W, vector<int>& V, int n, int w){
      | ^~~
a.cc: In function 'int main()':
a.cc:23:17: error: 'rec' was not declared in this scope
   23 |         cout << rec(W, V, n, w) << "\n";
      |                 ^~~
Language: C++

#define s second
#define pb(x) push_back(x)
typedef  long long  int ll;
typedef std::vector<ll> vi;

#define input(vec,a,b) for(ll i =a;i<b;i++) cin>>vec[i]
#define print(vec,a,b) for(ll i=a;i<b;i++) cout<<vec[i]<<" " ;cout<<endl;
#define all(a) a.begin(),a.end()
using namespace std;


void solve(){
        ll i,j , n,w,out;
        cin>>n>>w;
        ll we[n],v[n];
        for(i=0;i<n;i++)
        {
                 cin>>we[i]>>v[i];
        }
        ll mv[n+1][w+1]={0};
        bool p[n+1][w+1]={0};
        
        for(i=0;i<=w;i++)
        {
                 mv[0][i]=0;
                 
        }
        for(i=0;i<=n;i++)
        {
                 mv[i][0]=0;
                 p[i][0]=1;
        }
        
        for(i=1;i<=n;i++)
        {
                 for(j=0;j<we[i-1];j++)
                 {
                          p[i][j]=p[i-1][j];
                          mv[i][j]=mv[i-1][j];
                 }
                 for(j=we[i-1];j<=w;j++)
                 {
                          if(p[i-1][j-we[i-1]])
                          {
                                   mv[i][j]=max(mv[i-1][j],mv[i-1][j-we[i-1]]+v[i-1]);
                                   p[i][j]=1;
                          }
                          else
                          {
                                   mv[i][j]=mv[i-1][j];
                                   p[i][j]=p[i-1][j-1];
                          }
                 }
        }
        out=0;
        for(i=w;i>=0;i--)
        {
              out=max(out,mv[n][i]);
        }
        cout<<out;
}

int main()
{
      IO;
      ll t=1;
      //cin>>t;


      while(t--)
      {

          solve();
      }
    return 0;
}

Compiler output:
a.cc:4:14: error: 'vector' in namespace 'std' does not name a template type
    4 | typedef std::vector<ll> vi;
      |              ^~~~~~
a.cc:1:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
  +++ |+#include <vector>
    1 | #define s second
a.cc: In function 'void solve()':
a.cc:14:9: error: 'cin' was not declared in this scope
   14 |         cin>>n>>w;
      |         ^~~
a.cc:1:1: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
  +++ |+#include <iostream>
    1 | #define s second
a.cc:45:45: error: 'max' was not declared in this scope
   45 |                                    mv[i][j]=max(mv[i-1][j],mv[i-1][j-we[i-1]]+v[i-1]);
      |                                             ^~~
a.cc:58:19: error: 'max' was not declared in this scope
   58 |               out=max(out,mv[n][i]);
      |                   ^~~
a.cc:60:9: error: 'cout' was not declared in this scope
   60 |         cout<<out;
      |         ^~~~
a.cc:60:9: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc: In function 'int main()':
a.cc:65:7: error: 'IO' was not declared in this scope
   65 |       IO;
      |       ^~
Language: C++

#include<bits/stdc++.h>
using namespace std;

int main(){
  int n, W;
  cin >> n >> W;
  long long w[n], v[n];
  for(int i = 0; i < n; i++) cin >> w[i] >> v[i];
  long long dp[n + 1][w + 1];
  for(int i = 0; i <= W; i++) dp[0][i] = 0;
  for(int i = 0; i < n; i++){
    for(int j = 0; j <= W; j++){
      if(j >= w[i]) dp[i + 1][j] = max(dp[i][j - w[i]] + v[i], dp[i][j]);
      else dp[i + 1][j] = dp[i][j];
    }
  }
  cout << dp[n][w] << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:9:25: error: conversion from 'long long int*' to 'long unsigned int' in a converted constant expression
    9 |   long long dp[n + 1][w + 1];
      |                       ~~^~~
a.cc:9:25: error: could not convert '(((long long int*)(& w)) + 8)' from 'long long int*' to 'long unsigned int'
    9 |   long long dp[n + 1][w + 1];
      |                       ~~^~~
      |                         |
      |                         long long int*
a.cc:9:25: error: size of array 'dp' has non-integral type 'long long int*'
a.cc:17:16: error: invalid types 'long long int [1][long long int [n]]' for array subscript
   17 |   cout << dp[n][w] << endl;
      |                ^
Language: C++

#include<bits/stdc++.h>
using namespace std;

int main(){
  int n, w;
  cin >> n >> w;
  long long w[n], v[n];
  for(int i = 0; i < n; i++) cin >> w[i] >> v[i];
  long long dp[n + 1][w + 1];
  for(int i = 0; i <= w; i++) dp[0][i] = 0;
  for(int i = 0; i < n; i++){
    for(int j = 0; j <= w; j++){
      if(j >= w[i]) dp[i + 1][j] = max(dp[i][j - w[i]] + v[i], dp[i][j]);
      else dp[i + 1][j] = dp[i][j];
    }
  }
  cout << dp[n][w];
}

Compiler output:
a.cc: In function 'int main()':
a.cc:7:13: error: conflicting declaration 'long long int w [n]'
    7 |   long long w[n], v[n];
      |             ^
a.cc:5:10: note: previous declaration as 'int w'
    5 |   int n, w;
      |          ^
a.cc:8:38: error: invalid types 'int[int]' for array subscript
    8 |   for(int i = 0; i < n; i++) cin >> w[i] >> v[i];
      |                                      ^
a.cc:13:16: error: invalid types 'int[int]' for array subscript
   13 |       if(j >= w[i]) dp[i + 1][j] = max(dp[i][j - w[i]] + v[i], dp[i][j]);
      |                ^
a.cc:13:51: error: invalid types 'int[int]' for array subscript
   13 |       if(j >= w[i]) dp[i + 1][j] = max(dp[i][j - w[i]] + v[i], dp[i][j]);
      |                                                   ^
Language: C++

#include<bits/stdc++.h>
using namespace std;

int main(){
  int n, w;
  cin >> n >> w;
  long long w[n], v[n];
  for(int i = 0; i < n; i++) cin >> w[i] >> v[i];
  long long dp[n + 1][w + 1];
  for(int i = 0; i <= w; i++) dp[0][i] = 0;
  for(int i = 0; i < n; i++){
    for(int j = 0; j <= w; j++){
      if(j >= w[i]) dp[i + 1][j] = max(dp[i][j - w[i]] + v[i], dp[i][j]);
      else dp[i + 1][j] = dp[i][j];
    }
  }
  cout << dp[n][w];

Compiler output:
a.cc: In function 'int main()':
a.cc:7:13: error: conflicting declaration 'long long int w [n]'
    7 |   long long w[n], v[n];
      |             ^
a.cc:5:10: note: previous declaration as 'int w'
    5 |   int n, w;
      |          ^
a.cc:8:38: error: invalid types 'int[int]' for array subscript
    8 |   for(int i = 0; i < n; i++) cin >> w[i] >> v[i];
      |                                      ^
a.cc:13:16: error: invalid types 'int[int]' for array subscript
   13 |       if(j >= w[i]) dp[i + 1][j] = max(dp[i][j - w[i]] + v[i], dp[i][j]);
      |                ^
a.cc:13:51: error: invalid types 'int[int]' for array subscript
   13 |       if(j >= w[i]) dp[i + 1][j] = max(dp[i][j - w[i]] + v[i], dp[i][j]);
      |                                                   ^
a.cc:17:20: error: expected '}' at end of input
   17 |   cout << dp[n][w];
      |                    ^
a.cc:4:11: note: to match this '{'
    4 | int main(){
      |           ^
Language: C++

#include<bits/stdc++.h>
using namespace std;

int main()
{int n,W;
 cin>>n>>W;
 vector<pair<long long,long long>>v;
 for(int i=0;i<n;i++)
 {int a,b;
  cin>>a>>b;
 v.push_back({b,a});
 }int sm=0,wt=0
 sort(v.begin(),v.end());
 for(int i=0;i<n;i++)
 { wt=wt+v[i].second;
  if(wt<=W)
  sm=sm+v[i].first;
  else
  {wt=wt-v[i].second;
   continue;
     }
 }cout<<sm;
 }

Compiler output:
a.cc: In function 'int main()':
a.cc:13:2: error: expected ',' or ';' before 'sort'
   13 |  sort(v.begin(),v.end());
      |  ^~~~
Language: C++

#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
  cin>>n;
  vector<int>value(100001,0);
   vector<vector<int>> X(n+1,value);
  int w,v;
  vector<int> values;
  vector<int> weights;
  values.push_back(0);
  weight.push_back(0);
  for(int i=0;i<n;i++){
  cin>>v>>w;
    values.push_back(v);
    weights.push_back(w);
  }
  for(int i=1;i<n+1;i++){
  for(int j=1;j<=100001;j++){
  	if(j<weight[i]){
    X[i][j]=X[i-1][j];
    }
    else{
      X[i][j]=max(X[i-1][j],values[i]+X[i][j-weight[i]]);
    }
  }
  }
  cout<<X[n][1000001]<<"\n";
}

Compiler output:
a.cc: In function 'int main()':
a.cc:12:3: error: 'weight' was not declared in this scope; did you mean 'weights'?
   12 |   weight.push_back(0);
      |   ^~~~~~
      |   weights
Language: C++

#include <bits/stdc++.h>

#define ll long long

using namespace std;
 
void solve() {
    int n, w_max;
    cin >> n >> w_max;

    vector<ll> v(n), w(n);
    for (int i = 0; i < n; ++i) {
        cin >> w[i] >> v[i];
    }

    // dp[i][k] -> maior valor possível utilizando até o item i podendo usar
    //             até o peso k
    // dp[i][k] = max(inclui o i-ésimo, não inclui o i-ésimo)
    ll dp[n][w_max+1];
    memset(dp, -1ll, sizeof dp);

    function<ll(int, int)> calc_dp = [&] (int i, int k) {
        if (i < 0)
            return 0ll;
        if (dp[i][k] != -1)
            return dp[i][k];
        
        if (w[i] > k) {
            dp[i][k] = calc_dp(i-1, k);
        } else {
            dp[i][k] = max(v[i]+calc_dp(i-1, k - w[i]), calc_dp(i-1, k));
        }
        return dp[i][k];
    };

    cout << calc_dp(n-1, w_max) << endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    int t = 1;
    // cin >> t;

    for (int i = 0; i < t; ++i) {
        solve();
    }

    return 0;
}


Compiler output:
a.cc: In lambda function:
a.cc:25:13: sorry, unimplemented: capture of variably-modified type 'long long int [n][(w_max + 1)]' that is not an N3639 array of runtime bound
   25 |         if (dp[i][k] != -1)
      |             ^~
a.cc:25:13: note: because the array element type 'long long int [(w_max + 1)]' has variable size
a.cc:26:20: sorry, unimplemented: capture of variably-modified type 'long long int [n][(w_max + 1)]' that is not an N3639 array of runtime bound
   26 |             return dp[i][k];
      |                    ^~
a.cc:26:20: note: because the array element type 'long long int [(w_max + 1)]' has variable size
a.cc:29:13: sorry, unimplemented: capture of variably-modified type 'long long int [n][(w_max + 1)]' that is not an N3639 array of runtime bound
   29 |             dp[i][k] = calc_dp(i-1, k);
      |             ^~
a.cc:29:13: note: because the array element type 'long long int [(w_max + 1)]' has variable size
a.cc:31:13: sorry, unimplemented: capture of variably-modified type 'long long int [n][(w_max + 1)]' that is not an N3639 array of runtime bound
   31 |             dp[i][k] = max(v[i]+calc_dp(i-1, k - w[i]), calc_dp(i-1, k));
      |             ^~
a.cc:31:13: note: because the array element type 'long long int [(w_max + 1)]' has variable size
a.cc:33:16: sorry, unimplemented: capture of variably-modified type 'long long int [n][(w_max + 1)]' that is not an N3639 array of runtime bound
   33 |         return dp[i][k];
      |                ^~
a.cc:33:16: note: because the array element type 'long long int [(w_max + 1)]' has variable size
Language: Java


import java.util.*;

public class dp_d {
    public static void main(String args[]) {
    	Scanner in = new Scanner(System.in);
    	int n = in.nextInt(), w = in.nextInt();
        
        int[] val = new int[n];
        int[] wt = new int[n];
        for(int i = 0; i < n; i++)
        {
        	wt[i] = in.nextInt();
        	val[i] = in.nextInt();
        }

        // Populate base cases
        int[][] mat = new int[n + 1][w + 1];
        for (int r = 0; r < w + 1; r++) {
            mat[0][r] = 0;
        }
        for (int c = 0; c < n + 1; c++) {
            mat[c][0] = 0;
        }
        
        // Main logic
        for (int item = 1; item <= n; item++) {
            for (int capacity = 1; capacity <= w; capacity++) {
                int maxValWithoutCurr = mat[item - 1][capacity]; // This is guaranteed to exist
                int maxValWithCurr = 0; // We initialize this value to 0
                
                int weightOfCurr = wt[item - 1]; // We use item -1 to account for the extra row at the top
                if (capacity >= weightOfCurr) { // We check if the knapsack can fit the current item
                    maxValWithCurr = val[item - 1]; // If so, maxValWithCurr is at least the value of the current item
                    
                    int remainingCapacity = capacity - weightOfCurr; // remainingCapacity must be at least 0
                    maxValWithCurr += mat[item - 1][remainingCapacity]; // Add the maximum value obtainable with the remaining capacity
                }
                
                mat[item][capacity] = Math.max(maxValWithoutCurr, maxValWithCurr); // Pick the larger of the two
            }
        }
        
        System.out.println(mat[n][w]); // Final answer
    }
}

Compiler output:
Main.java:4: error: class dp_d is public, should be declared in a file named dp_d.java
public class dp_d {
       ^
1 error
Language: C++

#include <iostream>
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
    int n,wt;
    cin>>n>>wt;
    vector<ll> w(n);
    vector<ll> v(n);
    for(int i=0;i<n;i++)
    {
        cin>>w[i]>>v[i];
    } 

    ll dp[wt+1];
    memset(dp,0,sizeof(dp));

    for(int j=n-1;j>=0;j--)
    {
        for(int i=wt;i>a=0;i--)
        {
            if(i>=w[j])
            {
                dp[i]=max(dp[i],dp[i-w[j]]+v[j]);
            }
           // cout<<dp[i]<<endl;
        }
       // cout<<endl;
    }

    cout<<dp[wt]<<endl;
    return 0;
}
 

Compiler output:
a.cc: In function 'int main()':
a.cc:20:24: error: 'a' was not declared in this scope
   20 |         for(int i=wt;i>a=0;i--)
      |                        ^
Language: C++

#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll soln(vector<vector<int>>ans,int w){
    int n=ans.size();
    ll dp[n+1][w+1];
    for(int i=0;i<=n;i++)dp[i][0]=0;
    for(int i=0;i<=w;i++)dp[0][i]=0;
    dp[1][a[0][0]]=a[0][1];
    for(int i=2;i<=n;i++){
        for(int j=0;j<=w;j++){
            dp[i][j]=INT_MIN;
            if(j-a[i-1][0]>=0)dp[i][j]=a[i-1][1]+dp[i-1][j-a[i-1][0]];
            dp[i][j]=max(dp[i-1][j],dp[i][j]);
        }
    }
    return dp[n][w];
}
int main() {
    int t,k;cin>>t>>k;vector<vector<int>>ans;
    while(t--){
        int x,y;cin>>x>>y;
        ans.push_back({x,y});
    }
    cout<<soln(ans,k);
    return 0;
}

Compiler output:
a.cc: In function 'long long int soln(std::vector<std::vector<int> >, int)':
a.cc:9:11: error: 'a' was not declared in this scope
    9 |     dp[1][a[0][0]]=a[0][1];
      |           ^
Language: Java

import java.util.Scanner;
class Main
{
  public static long knapsack(int[] wt, long[] val, long n, long w, long[][] dp)
  {
    for(int i = 1; i <= n; i++)
    {
      for(int j = 1; j <= w; j++)
      {
        if(wt[i - 1] <= j)
        {
          dp[i][j] = Math.max((val[i - 1] + dp[i - 1][j - wt[i - 1]]), dp[i - 1][j]);
        }
        else
                                                      {
                                                        dp[i][j] = dp[i - 1][j];
                                                      }
                                                        
                                                      
      }
    }
                                                      return dp[n][w];
  }
  public static void main(String[] args)
  {
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    int w = scan.nextInt();
    int wt[] = new int[n];
    long val[] = new long[n];
    for(int i = 0; i < n; i++)
    {
      wt[i] = scan.nextInt();
      val[i] = scan.nextLong();
    }
    long[][] dp = new long[n + 1][w + 1];
    long maxProfit = knapsack(wt, val, n, w, dp);
    System.out.println(maxProfit);
  }
}


Compiler output:
Main.java:22: error: incompatible types: possible lossy conversion from long to int
                                                      return dp[n][w];
                                                                ^
Main.java:22: error: incompatible types: possible lossy conversion from long to int
                                                      return dp[n][w];
                                                                   ^
2 errors
Language: Java

import java.util.Scanner;
class Main
{
  public static long knapsack(int[] wt, long[] val, long n, long w, long[][] dp)
  {
    for(int i = 1; i <= n; i++)
    {
      for(int j = 1; j <= w; j++)
      {
        if(wt[i - 1] <= j)
        {
          dp[i][j] = Math.max((val[i - 1] + dp[i - 1][j - wt[i - 1]]), dp[i - 1][j]);
        }
        else
                                                      {
                                                        dp[i][j] = dp[i - 1][j];
                                                      }
                                                        
                                                      
      }
    }
                                                      return dp[n][w];
  }
  public static void main(String[] args)
  {
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    int w = scan.nextInt();
    int wt[] = new int[n];
    long val[] = new long[n];
    for(int i = 0; i < n; i++)
    {
      wt[i] = scan.nextInt();
      val[i] = scan.nextLong();
    }
    long[][] dp = new long[n + 1][w + 1];
    long maxProfit = knapsack(wt, val, n, w, dp);
    System.out.prlongln(maxProfit);
  }
}


Compiler output:
Main.java:22: error: incompatible types: possible lossy conversion from long to int
                                                      return dp[n][w];
                                                                ^
Main.java:22: error: incompatible types: possible lossy conversion from long to int
                                                      return dp[n][w];
                                                                   ^
Main.java:38: error: cannot find symbol
    System.out.prlongln(maxProfit);
              ^
  symbol:   method prlongln(long)
  location: variable out of type PrintStream
3 errors
Language: Java

import java.util.Scanner;
class Main
{
  public static long knapsack(long[] wt, long[] val, long n, long w, long[][] dp)
  {
    for(int i = 1; i <= n; i++)
    {
      for(int j = 1; j <= w; j++)
      {
        if(wt[i - 1] <= j)
        {
          dp[i][j] = Math.max((val[i - 1] + dp[i - 1][j - wt[i - 1]]), dp[i - 1][j]);
        }
        else
                                                      {
                                                        dp[i][j] = dp[i - 1][j];
                                                      }
                                                        
                                                      
      }
    }
                                                      return dp[n][w];
  }
  public static void main(String[] args)
  {
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    int w = scan.nextInt();
    long wt[] = new int[n];
    long val[] = new long[n];
    for(int i = 0; i < n; i++)
    {
      wt[i] = scan.nextlong();
      val[i] = scan.nextlong();
    }
    long[][] dp = new long[n + 1][w + 1];
    long maxProfit = knapsack(wt, val, n, w, dp);
    System.out.prlongln(maxProfit);
  }
}


Compiler output:
Main.java:12: error: incompatible types: possible lossy conversion from long to int
          dp[i][j] = Math.max((val[i - 1] + dp[i - 1][j - wt[i - 1]]), dp[i - 1][j]);
                                                        ^
Main.java:22: error: incompatible types: possible lossy conversion from long to int
                                                      return dp[n][w];
                                                                ^
Main.java:22: error: incompatible types: possible lossy conversion from long to int
                                                      return dp[n][w];
                                                                   ^
Main.java:29: error: incompatible types: int[] cannot be converted to long[]
    long wt[] = new int[n];
                ^
Main.java:33: error: cannot find symbol
      wt[i] = scan.nextlong();
                  ^
  symbol:   method nextlong()
  location: variable scan of type Scanner
Main.java:34: error: cannot find symbol
      val[i] = scan.nextlong();
                   ^
  symbol:   method nextlong()
  location: variable scan of type Scanner
Main.java:38: error: cannot find symbol
    System.out.prlongln(maxProfit);
              ^
  symbol:   method prlongln(long)
  location: variable out of type PrintStream
7 errors
Language: Java

import java.util.Scanner;
class Main
{
  public static long knapsack(long[] wt, long[] val, long n, long w, long[][] dp)
  {
    for(int i = 1; i <= n; i++)
    {
      for(int j = 1; j <= w; j++)
      {
        if(wt[i - 1] <= j)
        {
          dp[i][j] = Math.max((val[i - 1] + dp[i - 1][j - wt[i - 1]]), dp[i - 1][j]);
        }
        else
                                                      {
                                                        dp[i][j] = dp[i - 1][j];
                                                      }
                                                        
                                                      
      }
    }
                                                      return dp[n][w];
  }
  public static void main(String[] args)
  {
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    int w = scan.nextInt();
    long wt[] = new long[n];
    long val[] = new long[n];
    for(int i = 0; i < n; i++)
    {
      wt[i] = scan.nextlong();
      val[i] = scan.nextlong();
    }
    long[][] dp = new long[n + 1][w + 1];
    long maxProfit = knapsack(wt, val, n, w, dp);
    System.out.println(maxProfit);
  }
}


Compiler output:
Main.java:12: error: incompatible types: possible lossy conversion from long to int
          dp[i][j] = Math.max((val[i - 1] + dp[i - 1][j - wt[i - 1]]), dp[i - 1][j]);
                                                        ^
Main.java:22: error: incompatible types: possible lossy conversion from long to int
                                                      return dp[n][w];
                                                                ^
Main.java:22: error: incompatible types: possible lossy conversion from long to int
                                                      return dp[n][w];
                                                                   ^
Main.java:33: error: cannot find symbol
      wt[i] = scan.nextlong();
                  ^
  symbol:   method nextlong()
  location: variable scan of type Scanner
Main.java:34: error: cannot find symbol
      val[i] = scan.nextlong();
                   ^
  symbol:   method nextlong()
  location: variable scan of type Scanner
5 errors
Language: Java

import java.util.Scanner;
class Solution
{
  public static long knapsack(long[] wt, long[] val, long n, long w, long[][] dp)
  {
    for(int i = 1; i <= n; i++)
    {
      for(int j = 1; j <= w; j++)
      {
        if(wt[i - 1] <= j)
        {
          dp[i][j] = Math.max((val[i - 1] + dp[i - 1][j - wt[i - 1]]), dp[i - 1][j]);
        }
        else
                                                      {
                                                        dp[i][j] = dp[i - 1][j];
                                                      }
                                                        
                                                      
      }
    }
                                                      return dp[n][w];
  }
  public static void main(String[] args)
  {
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    int w = scan.nextInt();
    long wt[] = new long[n];
    long val[] = new long[n];
    for(int i = 0; i < n; i++)
    {
      wt[i] = scan.nextlong();
      val[i] = scan.nextlong();
    }
    long[][] dp = new long[n + 1][w + 1];
    long maxProfit = knapsack(wt, val, n, w, dp);
    System.out.prlongln(maxProfit);
  }
}


Compiler output:
Main.java:12: error: incompatible types: possible lossy conversion from long to int
          dp[i][j] = Math.max((val[i - 1] + dp[i - 1][j - wt[i - 1]]), dp[i - 1][j]);
                                                        ^
Main.java:22: error: incompatible types: possible lossy conversion from long to int
                                                      return dp[n][w];
                                                                ^
Main.java:22: error: incompatible types: possible lossy conversion from long to int
                                                      return dp[n][w];
                                                                   ^
Main.java:33: error: cannot find symbol
      wt[i] = scan.nextlong();
                  ^
  symbol:   method nextlong()
  location: variable scan of type Scanner
Main.java:34: error: cannot find symbol
      val[i] = scan.nextlong();
                   ^
  symbol:   method nextlong()
  location: variable scan of type Scanner
Main.java:38: error: cannot find symbol
    System.out.prlongln(maxProfit);
              ^
  symbol:   method prlongln(long)
  location: variable out of type PrintStream
6 errors
Language: Java

import java.util.Scanner;
class Solution
{
  public static int knapsack(int[] wt, int[] val, int n, int w, int[][] dp)
  {
 
  }
  public static void main(String[] args)
  {
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    int w = scan.nextInt();
    int wt[] = new int[n];
    int val[] = new int[n];
    for(int i = 0; i < n; i++)
    {
      wt[i] = scan.nextInt();
      val[i] = scan.nextInt();
    }
    int[][] dp = new int[n + 1][w + 1];
    for(int i = 1; i <= n; i++)
    {
      for(int j = 1; j <= w; j++)
      {
        if(wt[i - 1] <= j)
        {
          dp[i][j] = Math.max((val[i - 1] + dp[i - 1][j - wt[i - 1]]), dp[i - 1][j]);
        }
        else
                                                      {
                                                        dp[i][j] = dp[i - 1][j];
                                                      }
                                                        
                                                      
      }
    }
     int maxProfit = dp[n][w];
    System.out.println(maxProfit);
  }
}


Compiler output:
Main.java:7: error: missing return statement
  }
  ^
1 error
Language: Java

import java.util.Scanner;
class Solution
{
  public static int knapsack(int[] wt, int[] val, int n, int w, int[][] dp)
  {

  }
  public static void main(String[] args)
  {
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    int w = scan.nextInt();
    int wt[] = new int[n];
    int val[] = new int[n];
    for(int i = 0; i < n; i++)
    {
      wt[i] = scan.nextInt();
      val[i] = scan.nextInt();
    }
    int[][] dp = new int[n + 1][w + 1];
    for(int i = 1; i <= n; i++)
    {
      for(int j = 1; j <= w; j++)
      {
        if(wt[i - 1] <= j)
        {
          dp[i][j] = Math.max((val[i - 1] + dp[i - 1][j - wt[i - 1]]), dp[i - 1][j]);
        }
        else
                                                      {
                                                        dp[i][j] = dp[i - 1][j];
                                                      }
                                                        
                                                      
      }
    }
     int maxProfit = dp[n][w];
    System.out.println(maxProfit);
  }
}


Compiler output:
Main.java:7: error: missing return statement
  }
  ^
1 error
Language: Java

import java.util.Scanner;
class Solution
{
  public static int knapsack(int[] wt, int[] val, int n, int w, int[][] dp)
  {
    for(int i = 1; i <= n; i++)
    {
      for(int j = 1; j <= w; j++)
      {
        if(wt[i - 1] <= j)
        {
          dp[i][j] = Math.max((val[i - 1] + dp[i - 1][j - wt[i - 1]]), dp[i - 1][j]);
        }
        else
                                                      {
                                                        dp[i][j] = dp[i - 1][j]
                                                      }
                                                        
                                                      
      }
    }
                                                      return dp[n][w];
  }
  public static void main(String[] args)
  {
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    int w = scan.nextInt();
    int wt[] = new int[n];
    int val[] = new int[n];
    for(int i = 0; i < n; i++)
    {
      wt[i] = scan.nextInt();
      val[i] = scan.nextInt();
    }
    int[][] dp = new int[n + 1][w + 1];
    int maxProfit = knapsack(wt, val, n, w, dp);
    System.out.println(maxProfit);
  }
}

Compiler output:
Main.java:16: error: ';' expected
                                                        dp[i][j] = dp[i - 1][j]
                                                                               ^
1 error
Language: Java

import java.util.Scanner;
class Solution
{
  public static int knapsack(int[] wt, int[] val, int n, int w, int[][] dp)
  {
    for(int i = 1; i <= n; i++)
    {
      for(int j = 1; j <= w; j++)
      {
        if(wt[i - 1] <= j)
        {
          dp[i][j] = Math.max((val[i - 1] + dp[i - 1][j - wt[i - 1]), dp[i - 1][j]);
        }
        else
                                                      {
                                                        dp[i][j] = dp[i - 1][j];
                                                      }
                                                        
                                                      
      }
    }
                                                      return dp[n][w];
  }
  public static void main(String[] args)
  {
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    int w = scan.nextInt();
    int wt[] = new int[n];
    int val[] = new int[n];
    for(int i = 0; i < n; i++)
    {
      wt[i] = scan.nextInt();
      val[i] = scan.nextInt();
    }
    int[][] dp = new int[n + 1][w + 1];
    int maxProfit = knapsack(wt, val, n, w, dp);
    System.out.println(maxProfit);
  }
}

Compiler output:
Main.java:12: error: ']' expected
          dp[i][j] = Math.max((val[i - 1] + dp[i - 1][j - wt[i - 1]), dp[i - 1][j]);
                                                                   ^
1 error
Language: Java

import java.util.Scanner;
class Solution
{
  public static int knapsack(int[] wt, int[] val, int n, int w, int[][] dp)
  {
    for(int i = 1; i <= n; i++)
    {
      for(int j = 1; j <= w; j++)
      {
        if(wt[i - 1] <= j)
        {
          dp[i][j] = Math.max((val[i - 1] + dp[i - 1][j - wt[i - 1]), dp[i - 1][j]);
        }
        else
                                                      {
                                                        dp[i][j] = dp[i - 1][j]
                                                      }
                                                        
                                                      
      }
    }
                                                      return dp[n][w];
  }
  public static void main(String[] args)
  {
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    int w = scan.nextInt();
    int wt[] = new int[n];
    int val[] = new int[n];
    for(int i = 0; i < n; i++)
    {
      wt[i] = scan.nextInt();
      val[i] = scan.nextInt();
    }
    int[][] dp = new int[n + 1][w + 1];
    int maxProfit = knapsack(wt, val, n, w, dp);
    System.out.println(maxProfit);
  }
}

Compiler output:
Main.java:12: error: ']' expected
          dp[i][j] = Math.max((val[i - 1] + dp[i - 1][j - wt[i - 1]), dp[i - 1][j]);
                                                                   ^
Main.java:16: error: ';' expected
                                                        dp[i][j] = dp[i - 1][j]
                                                                               ^
2 errors
Language: C++

#include<bits/stdc++.h>
typedef long long ll;
#define pb push_back;
using namespace std;
int main()
{
    ll n,w,a,b;
    cin>>n>>w;
    pair<ll,ll> l[n];
    for(ll i=0;i<n;i++)
    {
        cin>>a>>b;
        l[i]={a,b};
    }
    ll m[n][w];
    for(int x=1;x<=w;x++)
    {
        for(int i=0;i<n;i++)
        {
            if (l[i].first<=x)
            {   if (i-1<0)
                    m[i][x]=l[i].second;
                else
                    {m[i][x]=max((m[i-1][x]),(l[i].second+m[i-1][x-(l[i].first])));}
            }
            else
            {   if (i-1<0)
                   m[i][x]=0;
                else
                  { m[i][x]=m[i-1][x];}
            }
        }
    }
    cout<<m[n-1][w]<<endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:24:79: error: expected ')' before ']' token
   24 |                     {m[i][x]=max((m[i-1][x]),(l[i].second+m[i-1][x-(l[i].first])));}
      |                                                                    ~          ^
      |                                                                               )
a.cc:24:83: error: expected ']' before ';' token
   24 |                     {m[i][x]=max((m[i-1][x]),(l[i].second+m[i-1][x-(l[i].first])));}
      |                                                                                   ^
      |                                                                                   ]
a.cc:24:83: error: expected ')' before ';' token
   24 |                     {m[i][x]=max((m[i-1][x]),(l[i].second+m[i-1][x-(l[i].first])));}
      |                                              ~                                    ^
      |                                                                                   )
a.cc:24:83: error: expected ')' before ';' token
   24 |                     {m[i][x]=max((m[i-1][x]),(l[i].second+m[i-1][x-(l[i].first])));}
      |                                 ~                                                 ^
      |                                                                                   )
Language: C++

#include <iostream>
using namespace std;
//long long int n,W;
//long long int dp[n+1][W+1];


            
        
     
int main() {
    long long int n,W;
    long long int dp[n+1][W+1];
    memset(dp,0,sizeof dp);

    cin>>n>>W;
   long long int arr[n+1],val[n+1];
    for(long long int i=1;i<=n;i++){
        cin>>arr[i]>>val[i];

    }
   // cout<<knapsack(arr,val,n,W);
   for(long long int i=1;i<=n;i++){
                for(long long int j=0;j<=W;j++){

            
        
             if(arr[i]<=j){
                dp[i][j]=max(val[i]+dp[i-1][j-arr[i]],dp[i-1][j]);
            }
             else {
                dp[i][j]=dp[i-1][j];
            }
        }
    }
    cout<< dp[n][W];


}


Compiler output:
a.cc: In function 'int main()':
a.cc:13:5: error: 'memset' was not declared in this scope
   13 |     memset(dp,0,sizeof dp);
      |     ^~~~~~
a.cc:2:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
    1 | #include <iostream>
  +++ |+#include <cstring>
    2 | using namespace std;