Language: C++

#include<bits/stdc++.h>
using namespace std;
#define int longl long
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];
}

// Driver program to test the cases
int32_t main()
{   int n , W ;
    cin >> n >> W ;
    int val[n] , wt[n];
    for(int x = 0 ; x < n ; x++ )
        cin >> wt[x] >> val[x];
   // int val[] = {7, 8, 4}, wt[] = {3, 8, 6}, W = 10, n = 3;
    cout << KnapSack(val, wt, n, W) << endl;
    return 0;
}


Compiler output:
a.cc:3:13: error: 'longl' does not name a type; did you mean 'long'?
    3 | #define int longl long
      |             ^~~~~
a.cc:4:1: note: in expansion of macro 'int'
    4 | int KnapSack(int val[], int wt[], int n, int W)
      | ^~~
a.cc: In function 'int32_t main()':
a.cc:3:13: error: 'longl' was not declared in this scope; did you mean 'long'?
    3 | #define int longl long
      |             ^~~~~
a.cc:54:5: note: in expansion of macro 'int'
   54 | {   int n , W ;
      |     ^~~
a.cc:55:12: error: 'n' was not declared in this scope; did you mean 'yn'?
   55 |     cin >> n >> W ;
      |            ^
      |            yn
a.cc:55:17: error: 'W' was not declared in this scope
   55 |     cin >> n >> W ;
      |                 ^
a.cc:3:19: error: expected ';' before 'long'
    3 | #define int longl long
      |                   ^~~~
a.cc:56:5: note: in expansion of macro 'int'
   56 |     int val[n] , wt[n];
      |     ^~~
a.cc:3:19: error: expected ';' before 'long'
    3 | #define int longl long
      |                   ^~~~
a.cc:57:9: note: in expansion of macro 'int'
   57 |     for(int x = 0 ; x < n ; x++ )
      |         ^~~
a.cc:57:21: error: 'x' was not declared in this scope
   57 |     for(int x = 0 ; x < n ; x++ )
      |                     ^
a.cc:58:16: error: 'wt' was not declared in this scope
   58 |         cin >> wt[x] >> val[x];
      |                ^~
a.cc:58:25: error: 'val' was not declared in this scope
   58 |         cin >> wt[x] >> val[x];
      |                         ^~~
a.cc:60:22: error: 'val' was not declared in this scope
   60 |     cout << KnapSack(val, wt, n, W) << endl;
      |                      ^~~
a.cc:60:27: error: 'wt' was not declared in this scope
   60 |     cout << KnapSack(val, wt, n, W) << endl;
      |                           ^~
a.cc:60:13: error: 'KnapSack' was not declared in this scope
   60 |     cout << KnapSack(val, wt, n, W) << endl;
      |             ^~~~~~~~