Language: C++

#include<bits/stdc++.h>
using namesapce std;
int knapsack(int a[],int b[],int w,int n){
  if(n==0 || w==0)
    return 0;
  if(w<b[n-1])
    return knapsack(a,b,w,n-1);
  else
    return max(a[n-1]+knapsack(a,b,w-b[n-1],n-1),knapsack(a,b,w,n-1));
}
int main(){
  int n,w;
  cin>>n>>w;
  int a[n];
  int b[n];
  for(int i=0;i<n;i++){
    cin>>a[i]>>b[i];
  }
  int ans;
  ans=knapsack(a,b,w,n);
  cout<<ans<<"\n";
  
}  
#include<bits/stdc++.h>
using namesapce std;
int knapsack(int a[],int b[],w,n){
  if(n==0 || w==0)
    return 0;
  if(w<b[n-1])
    return knapsack(a,b,w,n-1);
  else
    return max(a[n-1]+knapsack(a,b,w-b[n-1],n-1),knapsack(a,b,w,n-1));
}
int main(){
  int n,w;
  cin>>n>>w;
  int a[n];
  int b[n];
  for(int i=0;i<n;i++){
    cin>>a[i]>>b[i];
  }
  int ans;
  ans=knapsack(a,b,w,n);
  cout<<ans<<"\n";
  
}  

Compiler output:
a.cc:2:7: error: expected nested-name-specifier before 'namesapce'
    2 | using namesapce std;
      |       ^~~~~~~~~
a.cc: In function 'int knapsack(int*, int*, int, int)':
a.cc:9:12: error: 'max' was not declared in this scope; did you mean 'std::max'?
    9 |     return max(a[n-1]+knapsack(a,b,w-b[n-1],n-1),knapsack(a,b,w,n-1));
      |            ^~~
      |            std::max
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:1:
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: 'std::max' declared here
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
a.cc: In function 'int main()':
a.cc:13:3: error: 'cin' was not declared in this scope; did you mean 'std::cin'?
   13 |   cin>>n>>w;
      |   ^~~
      |   std::cin
In file included from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:146:
/usr/include/c++/14/iostream:62:18: note: 'std::cin' declared here
   62 |   extern istream cin;           ///< Linked to standard input
      |                  ^~~
a.cc:21:3: error: 'cout' was not declared in this scope; did you mean 'std::cout'?
   21 |   cout<<ans<<"\n";
      |   ^~~~
      |   std::cout
/usr/include/c++/14/iostream:63:18: note: 'std::cout' declared here
   63 |   extern ostream cout;          ///< Linked to standard output
      |                  ^~~~
a.cc: At global scope:
a.cc:25:7: error: expected nested-name-specifier before 'namesapce'
   25 | using namesapce std;
      |       ^~~~~~~~~
a.cc:26:30: error: 'w' has not been declared
   26 | int knapsack(int a[],int b[],w,n){
      |                              ^
a.cc:26:32: error: 'n' has not been declared
   26 | int knapsack(int a[],int b[],w,n){
      |                                ^
a.cc:26:5: error: redefinition of 'int knapsack(int*, int*, int, int)'
   26 | int knapsack(int a[],int b[],w,n){
      |     ^~~~~~~~
a.cc:3:5: note: 'int knapsack(int*, int*, int, int)' previously defined here
    3 | int knapsack(int a[],int b[],int w,int n){
      |     ^~~~~~~~
a.cc: In function 'int knapsack(int*, int*, int, int)':
a.cc:27:6: error: 'n' was not declared in this scope
   27 |   if(n==0 || w==0)
      |      ^
a.cc:27:14: error: 'w' was not declared in this scope
   27 |   if(n==0 || w==0)
      |              ^
a.cc:29:6: error: 'w' was not declared in this scope
   29 |   if(w<b[n-1])
      |      ^
a.cc:29:10: error: 'n' was not declared in this scope
   29 |   if(w<b[n-1])
      |          ^
a.cc:32:12: error: 'max' was not declared in this scope; did you mean 'std::max'?
   32 |     return max(a[n-1]+knapsack(a,b,w-b[n-1],n-1),knapsack(a,b,w,n-1));
      |            ^~~
      |            std::max
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: 'std::max' declared here
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
a.cc: At global scope:
a.cc:34:5: error: redefinition of 'int main()'
   34 | int main(){
      |     ^~~~
a.cc:11:5: note: 'int main()' previously defined here
   11 | int main(){
      |     ^~~~
a.cc: In function 'int main()':
a.cc:36:3: error: 'cin' was not declared in this scope; did you mean 'std::cin'?
   36 |   cin>>n>>w;
      |   ^~~
      |   std::cin
/usr/include/c++/14/iostream:62:18: note: 'std::cin' declared here
   62 |   extern istream cin;           ///< Linked to standard input
      |                  ^~~
a.cc:44:3: error: 'cout' was not declared in this scope; did you mean 'std::cout'?
   44 |   cout<<ans<<"\n";
      |   ^~~~
      |   std::cout
/usr/include/c++/14/iostream:63:18: note: 'std::cout' declared here
   63 |   extern ostream cout;          ///< Linked to standard output
      |                  ^~~~