Language: C++

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

long long int knapSack(int W, int wt[],long long  int val[], int n) 
{ 
    int i, w; 
    int K[n + 1][W + 1]; 
  
    // Build table K[][] in bottom up manner 
    for (i = 0; i <= n; i++) { 
        for (w = 0; w <= W; w++) { 
            if (i == 0 || w == 0) 
                K[i][w] = 0; 
            else if (wt[i - 1] <= w) 
                K[i][w] = max( 
                    val[i - 1] + K[i - 1][w - wt[i - 1]], 
                    K[i - 1][w]); 
            else
                K[i][w] = K[i - 1][w]; 
        } 
    } 
  
    return K[n][W]; 
} 
int main(){
 int n,w;
  cin>>n>>W;
  int a[n]'
    long long int arr[n];
  for(int i=0; i<n; i++){
   cin>>a[i]>>arr[i]; 
  }
  
  cout<<knapSack(w,a,arr,n);
  return 0;
}






Compiler output:
a.cc:29:11: warning: missing terminating ' character
   29 |   int a[n]'
      |           ^
a.cc:29:11: error: missing terminating ' character
a.cc: In function 'long long int knapSack(int, int*, long long int*, int)':
a.cc:16:30: error: no matching function for call to 'max(long long int, int&)'
   16 |                 K[i][w] = max(
      |                           ~~~^
   17 |                     val[i - 1] + K[i - 1][w - wt[i - 1]],
      |                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   18 |                     K[i - 1][w]);
      |                     ~~~~~~~~~~~~
In file included from /usr/include/c++/14/string:51,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:16:30: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   16 |                 K[i][w] = max(
      |                           ~~~^
   17 |                     val[i - 1] + K[i - 1][w - wt[i - 1]],
      |                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   18 |                     K[i - 1][w]);
      |                     ~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:2:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:16:30: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   16 |                 K[i][w] = max(
      |                           ~~~^
   17 |                     val[i - 1] + K[i - 1][w - wt[i - 1]],
      |                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   18 |                     K[i - 1][w]);
      |                     ~~~~~~~~~~~~
a.cc: In function 'int main()':
a.cc:28:11: error: 'W' was not declared in this scope
   28 |   cin>>n>>W;
      |           ^
a.cc:30:5: error: expected initializer before 'long'
   30 |     long long int arr[n];
      |     ^~~~
a.cc:32:9: error: 'a' was not declared in this scope
   32 |    cin>>a[i]>>arr[i];
      |         ^
a.cc:32:15: error: 'arr' was not declared in this scope
   32 |    cin>>a[i]>>arr[i];
      |               ^~~
a.cc:35:20: error: 'a' was not declared in this scope
   35 |   cout<<knapSack(w,a,arr,n);
      |                    ^
a.cc:35:22: error: 'arr' was not declared in this scope
   35 |   cout<<knapSack(w,a,arr,n);
      |                      ^~~