Language: C++

int KnapSack(int val[], int wt[], int n, int W) 
{ 
    // matrix to store final result 
    int mat[2][W+1]; 
    memset(mat, 0, sizeof(mat)); 
  
    // iterate through all items 
    int i = 0; 
    while (i < n) // one by one traverse each element 
    { 
        int j = 0; // traverse all weights j <= W 
  
        // if i is odd that mean till now we have odd 
        // number of elements so we store result in 1th 
        // indexed row 
        if (i%2!=0) 
        { 
            while (++j <= W) // check for each value 
            { 
                if (wt[i] <= j) // include element 
                    mat[1][j] = max(val[i] + mat[0][j-wt[i]], 
                                    mat[0][j] ); 
                else           // exclude element 
                    mat[1][j] = mat[0][j]; 
            } 
  
        } 
  
        // if i is even that mean till now we have even number 
        // of elements so we store result in 0th indexed row 
        else
        { 
            while(++j <= W) 
            { 
                if (wt[i] <= j) 
                    mat[0][j] = max(val[i] + mat[1][j-wt[i]], 
                                     mat[1][j]); 
                else
                    mat[0][j] = mat[1][j]; 
            } 
        } 
        i++; 
    } 
  
    // Return mat[0][W] if n is odd, else mat[1][W] 
    return (n%2 != 0)? mat[0][W] : mat[1][W]; 
} 

int main(){
	ll n,wt;
	cin>>n>>wt;
	int w[n];
	int v[n];
	int a,b;
	for(int i=0;i<n;i++){
		cin>>w[i]>>v[i];
		//w.pb(a); v.pb(b);
	}
	cout<<KnapSack(w,v,n,wt)<<endl;
}

Compiler output:
a.cc: In function 'int KnapSack(int*, int*, int, int)':
a.cc:5:5: error: 'memset' was not declared in this scope
    5 |     memset(mat, 0, sizeof(mat));
      |     ^~~~~~
a.cc:1:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
  +++ |+#include <cstring>
    1 | int KnapSack(int val[], int wt[], int n, int W)
a.cc:21:33: error: 'max' was not declared in this scope; did you mean 'mat'?
   21 |                     mat[1][j] = max(val[i] + mat[0][j-wt[i]],
      |                                 ^~~
      |                                 mat
a.cc:36:33: error: 'max' was not declared in this scope; did you mean 'mat'?
   36 |                     mat[0][j] = max(val[i] + mat[1][j-wt[i]],
      |                                 ^~~
      |                                 mat
a.cc: In function 'int main()':
a.cc:50:9: error: 'll' was not declared in this scope
   50 |         ll n,wt;
      |         ^~
a.cc:51:9: error: 'cin' was not declared in this scope
   51 |         cin>>n>>wt;
      |         ^~~
a.cc:51:14: error: 'n' was not declared in this scope
   51 |         cin>>n>>wt;
      |              ^
a.cc:51:17: error: 'wt' was not declared in this scope
   51 |         cin>>n>>wt;
      |                 ^~
a.cc:56:22: error: 'w' was not declared in this scope
   56 |                 cin>>w[i]>>v[i];
      |                      ^
a.cc:56:28: error: 'v' was not declared in this scope
   56 |                 cin>>w[i]>>v[i];
      |                            ^
a.cc:59:9: error: 'cout' was not declared in this scope
   59 |         cout<<KnapSack(w,v,n,wt)<<endl;
      |         ^~~~
a.cc:59:24: error: 'w' was not declared in this scope
   59 |         cout<<KnapSack(w,v,n,wt)<<endl;
      |                        ^
a.cc:59:26: error: 'v' was not declared in this scope
   59 |         cout<<KnapSack(w,v,n,wt)<<endl;
      |                          ^
a.cc:59:35: error: 'endl' was not declared in this scope
   59 |         cout<<KnapSack(w,v,n,wt)<<endl;
      |                                   ^~~~