Language: C++

#include<bits/stdc++.h>
using namesapce std;
int max(int a, int b) { return (a > b)? a : b; } 
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";
  
}  
#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";
  
}  
Submission Info

Compiler output:
a.cc:2:7: error: expected nested-name-specifier before 'namesapce'
    2 | using namesapce std;
      |       ^~~~~~~~~
a.cc:4:30: error: 'w' has not been declared
    4 | int knapsack(int a[],int b[],w,n){
      |                              ^
a.cc:4:32: error: 'n' has not been declared
    4 | int knapsack(int a[],int b[],w,n){
      |                                ^
a.cc: In function 'int knapsack(int*, int*, int, int)':
a.cc:5:6: error: 'n' was not declared in this scope
    5 |   if(n==0 || w==0)
      |      ^
a.cc:5:14: error: 'w' was not declared in this scope
    5 |   if(n==0 || w==0)
      |              ^
a.cc:7:6: error: 'w' was not declared in this scope
    7 |   if(w<b[n-1])
      |      ^
a.cc:7:10: error: 'n' was not declared in this scope
    7 |   if(w<b[n-1])
      |          ^
a.cc: In function 'int main()':
a.cc:14:3: error: 'cin' was not declared in this scope; did you mean 'std::cin'?
   14 |   cin>>n>>w;
      |   ^~~
      |   std::cin
In file included from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:146,
                 from a.cc:1:
/usr/include/c++/14/iostream:62:18: note: 'std::cin' declared here
   62 |   extern istream cin;           ///< Linked to standard input
      |                  ^~~
a.cc:22:3: error: 'cout' was not declared in this scope; did you mean 'std::cout'?
   22 |   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:26:7: error: expected nested-name-specifier before 'namesapce'
   26 | using namesapce std;
      |       ^~~~~~~~~
a.cc:27:30: error: 'w' has not been declared
   27 | int knapsack(int a[],int b[],w,n){
      |                              ^
a.cc:27:32: error: 'n' has not been declared
   27 | int knapsack(int a[],int b[],w,n){
      |                                ^
a.cc:27:5: error: redefinition of 'int knapsack(int*, int*, int, int)'
   27 | int knapsack(int a[],int b[],w,n){
      |     ^~~~~~~~
a.cc:4:5: note: 'int knapsack(int*, int*, int, int)' previously defined here
    4 | int knapsack(int a[],int b[],w,n){
      |     ^~~~~~~~
a.cc: In function 'int knapsack(int*, int*, int, int)':
a.cc:28:6: error: 'n' was not declared in this scope
   28 |   if(n==0 || w==0)
      |      ^
a.cc:28:14: error: 'w' was not declared in this scope
   28 |   if(n==0 || w==0)
      |              ^
a.cc:30:6: error: 'w' was not declared in this scope
   30 |   if(w<b[n-1])
      |      ^
a.cc:30:10: error: 'n' was not declared in this scope
   30 |   if(w<b[n-1])
      |          ^
a.cc: At global scope:
a.cc:35:5: error: redefinition of 'int main()'
   35 | int main(){
      |     ^~~~
a.cc:12:5: note: 'int main()' previously defined here
   12 | int main(){
      |     ^~~~
a.cc: In function 'int main()':
a.cc:37:3: error: 'cin' was not declared in this scope; did you mean 'std::cin'?
   37 |   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:45:3: error: 'cout' was not declared in this scope; did you mean 'std::cout'?
   45 |   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:48:1: error: 'Submission' does not name a type
   48 | Submission Info
      | ^~~~~~~~~~