criyle/codenet-compile-errors huggingface dataset:
Language: C

#include<stdio.h>
int main()
{	int n,W;
 	scanf("%d %d",&n,&W);
 	int i,j,w[n],v[n];
 	for(i=0;i<n;i++)
    {
      scanf("%d %d",&w[i],&v[i]);
    }
 	long dp[n][W+1];
 	for(i=0;i<n;i++)
    {	dp[i][0]=0;
    }
 	for(i=0;i<n;i++)
    	{	for(j=1;j<=W;j++)
    		{	if(i==0)
				{
					if(j<w[i])
					dp[i][j]=0;
					else
					dp[i][j]=v[0];
				}
				else
				{
      				if(j<w[i])
          			dp[i][j]=dp[i-1][j];
      				else 
        			{
          				if(dp[i-1][j]>=dp[i-1][j-w[i]]+v[i])
              				dp[i][j]=dp[i-1][j];
          				else
              				dp[i][j]=dp[i-1][j-w[i]]+v[i];
        			}  
    			}
    		}
		}	
 	printf("%d",dp[n-1][W]);
 	return 0;
}
#include<stdio.h>
int main()
{	int n,W;
 	scanf("%d %d",&n,&W);
 	int i,j,w[n],v[n];
 	for(i=0;i<n;i++)
    {
      scanf("%d %d",&w[i],&v[i]);
    }
 	long long dp[n][W+1];
 	for(i=0;i<n;i++)
    {	dp[i][0]=0;
    }
 	for(i=0;i<n;i++)
    	{	for(j=1;j<=W;j++)
    		{	if(i==0)
				{
					if(j<w[i])
					dp[i][j]=0;
					else
					dp[i][j]=v[0];
				}
				else
				{
      				if(j<w[i])
          			dp[i][j]=dp[i-1][j];
      				else 
        			{
          				if(dp[i-1][j]>=dp[i-1][j-w[i]]+v[i])
              				dp[i][j]=dp[i-1][j];
          				else
              				dp[i][j]=dp[i-1][j-w[i]]+v[i];
        			}  
    			}
    		}
		}	
 	printf("%d",dp[n-1][W]);
 	return 0;
}
Submission Info

Compiler output:
main.c:41:5: error: redefinition of 'main'
   41 | int main()
      |     ^~~~
main.c:2:5: note: previous definition of 'main' with type 'int()'
    2 | int main()
      |     ^~~~
main.c:79:1: error: unknown type name 'Submission'
   79 | Submission Info
      | ^~~~~~~~~~
main.c:79:1: error: expected '=', ',', ';', 'asm' or '__attribute__' at end of input
Language: C

#include<stdio.h>
int main()
{	int n,W;
 	scanf("%d %d",&n,&W);
 	int i,j,w[n],v[n];
 	for(i=0;i<n;i++)
    {
      scanf("%d %d",&w[i],&v[i]);
    }
 	int dp[n][w+1];
 	for(i=0;i<n;i++)
    {	dp[i][0]=0;
    }
 	for(i=0;i<n;i++)
    {	for(j=1;j<=W;j++)
    {	
      	if(j<w[i])
          dp[i][j]=dp[i-1][j];
      	else 
        {
          	if(dp[i-1][j]>=(dp[i-1][j-w[i]]+v[i]))
              dp[i][j]=dp[i-1][j];
          	else
              dp[i][j]=dp[i-1][j-w[i]]+v[i];
        }  
    }
    }
 	printf("%d",dp[n-1][W]);
 	return 0;
}
 	
 	

Compiler output:
main.c: In function 'main':
main.c:10:13: error: size of array 'dp' has non-integer type
   10 |         int dp[n][w+1];
      |             ^~
Language: C

#include<stdio.h>
int main()
{	int n,w;
 	scanf("%d %d",&n,&w);
 	int i,j,w[n],v[n];
 	for(i=0;i<n;i++)
    {
      scanf("%d %d",&w[i],&v[i]);
    }
 	int dp[n][w+1];
 	for(i=0;i<n;i++)
    {	dp[i][0]=0;
    }
 	for(i=0;i<n;i++)
    {	for(j=1;j<=w;j++)
    {	
      	if(j<w[i])
          dp[i][j]=dp[i-1][j];
      	else 
        {
          	if(dp[i-1][j]>=(dp[i-1][j-w[i]]+v[i]))
              dp[i][j]=dp[i-1][j];
          	else
              dp[i][j]=dp[i-1][j-w[i]]+v[i];
        }  
    }
    }
 	printf("%d",dp[n-1][w]);
 	return 0;
}
 	
 	

Compiler output:
main.c: In function 'main':
main.c:5:17: error: conflicting types for 'w'; have 'int[n]'
    5 |         int i,j,w[n],v[n];
      |                 ^
main.c:3:15: note: previous declaration of 'w' with type 'int'
    3 | {       int n,w;
      |               ^
Language: C++

#include <iostream>
#define ll long long
using namespace std;

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, i, j, w, W;
  cin >> n >> W;
  int weights[n], values[n];
  for (i = 0; i < n; i++)
    cin >> weights[i] >> values[i];

  ll dp[n + 1][100001];
  memset(dp, 0, sizeof(dp));

  for (i = 1; i <= n; i++)
  {
    for (w = 1; w <= W; w++)
    {
      if (w < weights[i - 1])
      {
        dp[i][w] = max(dp[i][w - 1], dp[i - 1][w]);
      }
      else
      {
        dp[i][w] = max(dp[i - 1][w], dp[i - 1][w - weights[i - 1]] + values[i - 1]);
      }
    }
  }
  cout << dp[n][W] << endl;
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:16:3: error: 'memset' was not declared in this scope
   16 |   memset(dp, 0, sizeof(dp));
      |   ^~~~~~
a.cc:2:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
    1 | #include <iostream>
  +++ |+#include <cstring>
    2 | #define ll long long
Language: C++

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

int main()
{
  int n;
  cin >> n >> w;
  int wei[n+1], val[n+1], dp[n+1][w+1]={}; 
  for(int i=1; i<=n; i++) cin >> wei[i] >> val[i];
  for(int i=1; i<=n; i++)
  {
    for(int j=1; j<=w; j++)
    {
      if(j>=wei[i]) dp[i][j] = max(dp[i-1][j], dp[i-1][j-wei[i]] + val[i]);
      else dp[i][j] = dp[i-1][j];
    }
  }
  cout << dp[n][w];
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:7:15: error: 'w' was not declared in this scope
    7 |   cin >> n >> w;
      |               ^
a.cc:14:21: error: 'dp' was not declared in this scope; did you mean 'dup'?
   14 |       if(j>=wei[i]) dp[i][j] = max(dp[i-1][j], dp[i-1][j-wei[i]] + val[i]);
      |                     ^~
      |                     dup
a.cc:15:12: error: 'dp' was not declared in this scope; did you mean 'dup'?
   15 |       else dp[i][j] = dp[i-1][j];
      |            ^~
      |            dup
a.cc:18:11: error: 'dp' was not declared in this scope; did you mean 'dup'?
   18 |   cout << dp[n][w];
      |           ^~
      |           dup
Language: C++

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define faster ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define cint int t;cin>>t;while(t--)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define vint vector<int>
#define all(v) (v).begin(), (v).end()
#define pii pair<int,int>
#define pb push_back
const int N=1e5+5;
int mod=1e9+7;

int n,w;
int W[N],v[N];
int cache[105][N];

int dp(int idx,int wt){


    if(wt>w) {
//        cout<<"ehi";
        return INT64_MIN;
    }
    if(idx>=n) return 0;



    ans=max(dp(idx+1,wt),v[idx]+dp(idx+1,wt+W[idx]));

    return ans;
}

int32_t main() {
    faster;


    cin>>n>>w;

    memset(cache,-1,sizeof(cache));

    for(int i=0;i<n;i++){
        cin>>W[i]>>v[i];
    }

    cout<<dp(0,0)<<endl;
}

Compiler output:
a.cc: In function 'long long int dp(long long int, long long int)':
a.cc:31:5: error: 'ans' was not declared in this scope; did you mean 'abs'?
   31 |     ans=max(dp(idx+1,wt),v[idx]+dp(idx+1,wt+W[idx]));
      |     ^~~
      |     abs
Language: C++

#include<bits/stdc++.h>
using namespace std;
//#define int long long int
#define nitro ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
#define pb push_back
#define PI 3.1415926535897932384626
#define MOD 1000000007
#define DEBUG false
#pragma GCC optimize "trapv"

void solve(int n,int wt[],int val[],int W)
{
    int K[n+1][W+1],i; 
   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]; 
       } 
   }
   cout<<K[n][W]<<'\n';
}
int main()
{
    nitro;
    int n,W,x,y;
    cin>>n>>W;
    int wt[n],val[n];
    for(int i=0;i<n;i++)
    {
        cin>>x>>y;
        wt[i]=x;
        val[i]=y;
    }
    solve(n,wt,val,W);
return 0;
}

Compiler output:
a.cc: In function 'void solve(int, int*, int*, int)':
a.cc:16:13: error: 'w' was not declared in this scope
   16 |        for (w = 0; w <= W; w++)
      |             ^
Language: C++

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

int main() {
  int N;
  cin >> N;
  vector<int> w(N),v(N);
  for(int i=0;i<N;i++){
    cin >> w[i] >> v[i];
  }
  vector<vector<long long>> dp(N+1,vector<long long>(M+1,0));
  
  for(int i=0;i<N;i++){
    for(int j=0;j<=W;j++){
      if(j<w[i])
        dp[i+1][j]=dp[i][j];
      else
        dp[i+1][j]=max(dp[i][j],dp[i][j-w[i]]+v[i]);
    }
  }
  cout << dp[N][W] << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:11:54: error: 'M' was not declared in this scope
   11 |   vector<vector<long long>> dp(N+1,vector<long long>(M+1,0));
      |                                                      ^
a.cc:14:20: error: 'W' was not declared in this scope
   14 |     for(int j=0;j<=W;j++){
      |                    ^
a.cc:21:17: error: 'W' was not declared in this scope
   21 |   cout << dp[N][W] << endl;
      |                 ^
Language: C++

#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,w;
  cin>>n>>w;
  int a[n+1][2];
  for(int i=1;i<=n;i++)
    cin>>a[i][0]>>a[i][1];
  int dp[w+1];
  for(int i=1;i<=n;i++)
  {
    for(int j=w-a[i][0];j>0;j-=1)
    {
      dp[j+a[i][0]]=max(dp[j+a[i][0],a[i][1]+dp[j]);
                           }
                           }
       cout<<dp[w];
                           return 0;
                           }
        


Compiler output:
a.cc: In function 'int main()':
a.cc:15:51: error: expected ']' before ')' token
   15 |       dp[j+a[i][0]]=max(dp[j+a[i][0],a[i][1]+dp[j]);
      |                                                   ^
      |                                                   ]
a.cc:15:24: error: no matching function for call to 'max(int&)'
   15 |       dp[j+a[i][0]]=max(dp[j+a[i][0],a[i][1]+dp[j]);
      |                     ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 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:   candidate expects 2 arguments, 1 provided
/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, 1 provided
In file included from /usr/include/c++/14/algorithm:61:
/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:   template argument deduction/substitution failed:
a.cc:15:24: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   15 |       dp[j+a[i][0]]=max(dp[j+a[i][0],a[i][1]+dp[j]);
      |                     ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/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:   candidate expects 2 arguments, 1 provided
Language: C++

#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,w;
  cin>>n>>w;
  int a[n+1][2];
  for(int i=1;i<=n;i++)
    cin>>a[i][0]>>a[i][1];
  
  for(int i=1;i<=n;i++)
  {
    for(int j=w-a[i][0];j>0;j-=1)
    {
      dp[j+a[i][0]]=max(dp[j+a[i][0],a[i][1]+dp[j]);
                           }
                           }
       cout<<dp[w];
                           return 0;
                           }
        

Compiler output:
a.cc: In function 'int main()':
a.cc:15:7: error: 'dp' was not declared in this scope; did you mean 'dup'?
   15 |       dp[j+a[i][0]]=max(dp[j+a[i][0],a[i][1]+dp[j]);
      |       ^~
      |       dup
a.cc:15:51: error: expected ']' before ')' token
   15 |       dp[j+a[i][0]]=max(dp[j+a[i][0],a[i][1]+dp[j]);
      |                                                   ^
      |                                                   ]
a.cc:18:14: error: 'dp' was not declared in this scope; did you mean 'dup'?
   18 |        cout<<dp[w];
      |              ^~
      |              dup
Language: C++

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

int main()
{
  int n, W;
  cin >> n >> W;
  int w[n+1], val[n+1];
  for(int i=1; i<=n; i++) cin >> w[i] >> val[i];
  int dp[w+1][n+1]={};
  for(int i=1; i<=W; i++)
  {
    for(int j=1; j<=n; j++)
    {
      if(w[j]<=i) dp[i][j] = max(dp[i][j], dp[i-w[j]][j-1] + val[j]);
    }
  }
  cout << dp[W][n];
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:10:11: error: conversion from 'int*' to 'long unsigned int' in a converted constant expression
   10 |   int dp[w+1][n+1]={};
      |          ~^~
a.cc:10:11: error: could not convert '(((int*)(& w)) + 4)' from 'int*' to 'long unsigned int'
   10 |   int dp[w+1][n+1]={};
      |          ~^~
      |           |
      |           int*
a.cc:10:11: error: size of array 'dp' has non-integral type 'int*'
Language: C++

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

int main()
{
  int n, w;
  cin >> n >> W;
  int w[n+1], val[n+1];
  for(int i=1; i<=n; i++) cin >> w[i] >> val[i];
  int dp[w+1][n+1]={};
  for(int i=1; i<=W; i++)
  {
    for(int j=1; j<=n; j++)
    {
      if(w[j]<=i) dp[i][j] = max(dp[i][j], dp[i-w[j]][j-1] + val[j]);
    }
  }
  cout << dp[W][n];
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:7:15: error: 'W' was not declared in this scope
    7 |   cin >> n >> W;
      |               ^
a.cc:8:7: error: conflicting declaration 'int w [(n + 1)]'
    8 |   int w[n+1], val[n+1];
      |       ^
a.cc:6:10: note: previous declaration as 'int w'
    6 |   int n, w;
      |          ^
a.cc:9:35: error: invalid types 'int[int]' for array subscript
    9 |   for(int i=1; i<=n; i++) cin >> w[i] >> val[i];
      |                                   ^
a.cc:15:11: error: invalid types 'int[int]' for array subscript
   15 |       if(w[j]<=i) dp[i][j] = max(dp[i][j], dp[i-w[j]][j-1] + val[j]);
      |           ^
a.cc:15:50: error: invalid types 'int[int]' for array subscript
   15 |       if(w[j]<=i) dp[i][j] = max(dp[i][j], dp[i-w[j]][j-1] + val[j]);
      |                                                  ^
Language: C++

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

int main()
{
  int n, w;
  cin >> n >> w;
  int w[n+1], val[n+1];
  for(int i=1; i<=n; i++) cin >> w[i] >> val[i];
  int dp[w+1][n+1]={};
  for(int i=1; i<=w; i++)
  {
    for(int j=1; j<=n; j++)
    {
      if(w[j]<=i) dp[i][j] = max(dp[i][j], dp[i-w[j]][j-1] + val[j]);
    }
  }
  cout << dp[w][n];
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:8:7: error: conflicting declaration 'int w [(n + 1)]'
    8 |   int w[n+1], val[n+1];
      |       ^
a.cc:6:10: note: previous declaration as 'int w'
    6 |   int n, w;
      |          ^
a.cc:9:35: error: invalid types 'int[int]' for array subscript
    9 |   for(int i=1; i<=n; i++) cin >> w[i] >> val[i];
      |                                   ^
a.cc:15:11: error: invalid types 'int[int]' for array subscript
   15 |       if(w[j]<=i) dp[i][j] = max(dp[i][j], dp[i-w[j]][j-1] + val[j]);
      |           ^
a.cc:15:50: error: invalid types 'int[int]' for array subscript
   15 |       if(w[j]<=i) dp[i][j] = max(dp[i][j], dp[i-w[j]][j-1] + val[j]);
      |                                                  ^
Language: Java

import java.util.Scanner;

import static java.lang.Math.max;


public class MainApp{

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int w = scan.nextInt();
        long[] weight = new long[n + 1];
        long[] value = new long[n + 1];
        long[] dp = new long[w + 1];
        for (int i = 1; i <= n; i++) {
            weight[i] = scan.nextLong();
            value[i] = scan.nextLong();
        }

        // dp[i][j]  表示选到第i个物品时剩余j容量的最大价值
        for (long i = 1; i <= n; i++) {
            for (long j = w; j >= 0; j--) {
                if(j >= weight[(int)i]) {
                    dp[(int)j] = max(dp[(int)j], dp[(int)(j-weight[(int)i])] + value[(int)i]);
                } else {
                }
            }
        }
        System.out.println(dp[w]);
    }


}

Compiler output:
Main.java:6: error: class MainApp is public, should be declared in a file named MainApp.java
public class MainApp{
       ^
1 error
Language: Java

import java.util.Scanner;

import static java.lang.Math.max;


public class MainApp{

    public static void main(String[] args) throws InterruptedException {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int w = scan.nextInt();
        int[] weight = new int[n + 1];
        int[] value = new int[n + 1];
        int[] dp = new int[w + 1];
        for (int i = 1; i <= n; i++) {
            weight[i] = scan.nextInt();
            value[i] = scan.nextInt();
        }

        // dp[i][j]  表示选到第i个物品时剩余j容量的最大价值
        for (int i = 1; i <= n; i++) {
            for (int j = w; j >= 0; j--) {
                if(j >= weight[i]) {
                    dp[j] = max(dp[j], dp[j-weight[i]] + value[i]);
                } else {
                }
            }
        }
        System.out.println(dp[w]);
    }


}

Compiler output:
Main.java:6: error: class MainApp is public, should be declared in a file named MainApp.java
public class MainApp{
       ^
1 error
Language: Java



import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider;

import java.util.Scanner;

import static java.lang.Math.max;


public class MainApp extends ClassPathScanningCandidateComponentProvider{

    public static void main(String[] args) throws InterruptedException {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int w = scan.nextInt();
        int[] weight = new int[n + 1];
        int[] value = new int[n + 1];
        int[][] dp = new int[n + 1][w + 1];
        for (int i = 1; i <= n; i++) {
            weight[i] = scan.nextInt();
            value[i] = scan.nextInt();
        }

        // dp[i][j]  表示选到第i个物品时剩余j容量的最大价值
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= w; j++) {
                if(j >= weight[i]) {
                   dp[i][j] = max(dp[i][j], dp[i-1][j-weight[i]] + value[i]);
                } else {
                   dp[i][j] = dp[i-1][j];
                }
            }
        }
        System.out.println(dp[n][w]);
    }


}

Compiler output:
Main.java:10: error: class MainApp is public, should be declared in a file named MainApp.java
public class MainApp extends ClassPathScanningCandidateComponentProvider{
       ^
Main.java:3: error: package org.springframework.context.annotation does not exist
import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider;
                                             ^
Main.java:10: error: cannot find symbol
public class MainApp extends ClassPathScanningCandidateComponentProvider{
                             ^
  symbol: class ClassPathScanningCandidateComponentProvider
3 errors
Language: C++

#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,w;
  cin>>n>>w;
  long long int arr[n+1][w+1];
  long long int v1[n],w1[n],answer;
  for(int i=0;i<n;i++){
  cin>>w1[i]>>v1[i];
  }
  for(int i=0;i<n;i++){
  for(int j=0;j<=w;j++){
  if(i==0||j==0){
  arr[i][j]=0;
  }
    else if(j>=w1[i-1]){
    arr[i][j]=max(v1[i-1]+arr[i-1][j-w1[i-1]],arr[i-1][j])
    }
    else{
    arr[i][j]=arr[i-1][j];
    }
  }
  }
  cout<<arr[n][w];
return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:17:59: error: expected ';' before '}' token
   17 |     arr[i][j]=max(v1[i-1]+arr[i-1][j-w1[i-1]],arr[i-1][j])
      |                                                           ^
      |                                                           ;
   18 |     }
      |     ~
Language: C++

#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,w;
  cin>>n>>w;
  long long int arr[n+1][w+1]
  memset(arr,-1,sizeof(arr));
  long long int v1[n],w1[n],answer;
  for(int i=0;i<n;i++){
  cin>>w1[i]>>v1[i];
  }
  for(int i=0;i<n;i++){
  for(int j=0;j<=w;j++){
  if(i==0||j==0){
  arr[i][j]=0;
  }
    else if(j>=w1[i-1]){
    arr[i][j]=max(v1[i-1]+arr[i-1][j-w1[i-1]],arr[i-1][j])
    }
    else{
    arr[i][j]=arr[i-1][j];
    }
  }
  }
  cout<<arr[n][w];
return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:7:3: error: expected initializer before 'memset'
    7 |   memset(arr,-1,sizeof(arr));
      |   ^~~~~~
a.cc:15:3: error: 'arr' was not declared in this scope
   15 |   arr[i][j]=0;
      |   ^~~
a.cc:18:5: error: 'arr' was not declared in this scope
   18 |     arr[i][j]=max(v1[i-1]+arr[i-1][j-w1[i-1]],arr[i-1][j])
      |     ^~~
a.cc:21:5: error: 'arr' was not declared in this scope
   21 |     arr[i][j]=arr[i-1][j];
      |     ^~~
a.cc:25:9: error: 'arr' was not declared in this scope
   25 |   cout<<arr[n][w];
      |         ^~~
Language: C++

#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,w;
  cin>>n>>w;
  long long int arr[n+1][w+1]
  memset(arr,-1,sizeof(arr));
  long long int v1[n],w1[n],answer;
  for(int i=0;i<n;i++){
  cin>>w1[i]>>v1[i];
  }
  for(int i=0;i<n;i++){
  for(int j=0;j<=w;j++){
  if(i==0||j==0){
  arr[i][j]=0;
  }
    else if(j>=w1[i-1]){
    arr[i][j]=max(v1[i-1]+arr[i-1][j-w1[i-1]],arr[i-1][j])
    }
    else{
    arr[i][j]=arr[i-1][j];
    }
  }
  }
  cout<<answer;
return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:7:3: error: expected initializer before 'memset'
    7 |   memset(arr,-1,sizeof(arr));
      |   ^~~~~~
a.cc:15:3: error: 'arr' was not declared in this scope
   15 |   arr[i][j]=0;
      |   ^~~
a.cc:18:5: error: 'arr' was not declared in this scope
   18 |     arr[i][j]=max(v1[i-1]+arr[i-1][j-w1[i-1]],arr[i-1][j])
      |     ^~~
a.cc:21:5: error: 'arr' was not declared in this scope
   21 |     arr[i][j]=arr[i-1][j];
      |     ^~~
Language: C++

#include<bits/stdc++.h>
using namespace std;
int find(vector<vector<int>> v1,int n,int  i,vector<vector<int>> v2){
	if(i==v1.size()||n==0) return 0;
  	if(v2[n][i]!=-1) return v2[n][i];
  	int n1=INT_MIN,n2=INT_MIN;
    if(n-v1[i][0]>=0){
      n1=find(v1,n-v1[i][0],i+1,v2)+v1[i][1];
    }
  	return v2[n][i]=max(n1,find(v1,n,i+1,v2));
}
int main(){
  int n,k;
  cin>>n>>k;
  vector<vector<int>> v1(n,vector<int> (2));
  for(int i=0;i<n;i++){
    cin>>v1[i][0]>>v1[i][1];
  }
  cout<<find(v1,k,0);
}


Compiler output:
a.cc: In function 'int main()':
a.cc:19:13: error: no matching function for call to 'find(std::vector<std::vector<int> >&, int&, int)'
   19 |   cout<<find(v1,k,0);
      |         ~~~~^~~~~~~~
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:3842:5: note: candidate: 'template<class _IIter, class _Tp> _IIter std::find(_IIter, _IIter, const _Tp&)'
 3842 |     find(_InputIterator __first, _InputIterator __last,
      |     ^~~~
/usr/include/c++/14/bits/stl_algo.h:3842:5: note:   template argument deduction/substitution failed:
a.cc:19:13: note:   deduced conflicting types for parameter '_IIter' ('std::vector<std::vector<int> >' and 'int')
   19 |   cout<<find(v1,k,0);
      |         ~~~~^~~~~~~~
In file included from /usr/include/c++/14/algorithm:86:
/usr/include/c++/14/pstl/glue_algorithm_defs.h:60:1: note: candidate: 'template<class _ExecutionPolicy, class _ForwardIterator, class _Tp> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator> std::find(_ExecutionPolicy&&, _ForwardIterator, _ForwardIterator, const _Tp&)'
   60 | find(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value);
      | ^~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:60:1: note:   candidate expects 4 arguments, 3 provided
In file included from /usr/include/c++/14/iterator:66,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:54:
/usr/include/c++/14/bits/streambuf_iterator.h:435:5: note: candidate: 'template<class _CharT2> typename __gnu_cxx::__enable_if<std::__is_char<_CharT2>::__value, std::istreambuf_iterator<_CharT, std::char_traits<_CharT> > >::__type std::find(istreambuf_iterator<_CharT, char_traits<_CharT> >, istreambuf_iterator<_CharT, char_traits<_CharT> >, const _CharT2&)'
  435 |     find(istreambuf_iterator<_CharT> __first,
      |     ^~~~
/usr/include/c++/14/bits/streambuf_iterator.h:435:5: note:   template argument deduction/substitution failed:
a.cc:19:13: note:   'std::vector<std::vector<int> >' is not derived from 'std::istreambuf_iterator<_CharT, std::char_traits<_CharT> >'
   19 |   cout<<find(v1,k,0);
      |         ~~~~^~~~~~~~
a.cc:3:5: note: candidate: 'int find(std::vector<std::vector<int> >, int, int, std::vector<std::vector<int> >)'
    3 | int find(vector<vector<int>> v1,int n,int  i,vector<vector<int>> v2){
      |     ^~~~
a.cc:3:5: note:   candidate expects 4 arguments, 3 provided
Language: C++

#include<bits/stdc++.h> 
using namespace std;
 
int main()
{
  int i,j,n,p,x=0,k;
  cin>>n;
  cin>>p;
  int w[n],v[n],y[n];
  for(i=0;i<n;i++)
  {
    cin>>w[i];
    cin>>v[i];
  }
  for(i=0;i<n;i++)
  {
    x=x+w[i];
    if(x<=p)
    {
      if(i>0)
      	y[i]=y[i-1]+v[i];
      else
       	y[i]=v[0];
    }
    else
    {
      x=x-w[i];
      for(k=0;k<i;k++)
      {
        if(v[i]>v[k] && w[i]<w[k])
        {
          y[i]=y[i-1]-v[k]+v[i];
          swap(w[i],w[k]);
          swap(v[i],v[k]);
      	}
    }
  }
    cout<<y[n-1]<<endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:39:2: error: expected '}' at end of input
   39 | }
      |  ^
a.cc:5:1: note: to match this '{'
    5 | {
      | ^
Language: C++

#include<bits/stdc++.h>
#define int long long
#define rep(i,a,b) for(int i=a;i<b;i+=1)
#define vi vector<int>
using namespace std;

int helper(int n, int w, int *weights, int *values){
	
	int ans[2][w+1];
	rep(i, 0, w+1) ans[0][i] = 0;
	
	int res = 1;
	rep(i, 1, n+1)
	{
		rep(j, 0, w+1)
		{
			if(weights[i-1][j] <= w) ans[res][j] = max(values[i-1]+ans[res^1][w-weights[i-1]], ans[res^1][j]);
			else ans[res][j] = ans[res^1][j];
		}
		res = res^1;
	}
	return ans[res^1][w];
}

int32_t main(void){
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	
	int n, w;
	cin>>n>>w;
	int *weights = new int[n];
	int *values = new int[n];
	
	rep(i, 0, n) cin>>weights[i]>>values[i];
	cout<<helper(n, w, weights, values)<<endl;
	
	delete [] weights;
	delete [] values;
}

Compiler output:
a.cc: In function 'long long int helper(long long int, long long int, long long int*, long long int*)':
a.cc:17:40: error: invalid types 'long long int[long long int]' for array subscript
   17 |                         if(weights[i-1][j] <= w) ans[res][j] = max(values[i-1]+ans[res^1][w-weights[i-1]], ans[res^1][j]);
      |                                        ^
Language: C++

/*
Author:Jenil Mehta
Not yet serious but trying to be serious :)
Coding is lub
*/
 
#include <iostream>
#include <sstream>
#include <cstdio>
#include <climits>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
typedef long long int ll;
ll power(ll a, ll n) {ll p = 1;while (n > 0) {if(n%2) {p = p * a;} n >>= 1; a *= a;} return p;}
ll power(ll a, ll n, ll mod) {ll p = 1;while (n > 0) {if(n%2) {p = p * a; p %= mod;} n >>= 1; a *= a; a %= mod;} return p % mod;}
using namespace std;
int main()
{
    ll n;
    cin>>n;
    ll w;
    cin>>w;
    ll a[n+1];
    ll b[n+1];
    ll i,j;
    ll ans=0;
    ll index=0;
    ll dp[n+1][w+1];
    for(i=0;i<n;i++)
    {
        cin>>a[i]>>b[i];
    }
    if (n == 0 || W == 0) 
    {
        cout<<0<<endl;
        return 0;
    }
    //cout<<"hello1"<<endl;
    for(i=0;i<=n;i++)
    {
        //cout<<"hello2"<<endl;
        for(j=0;j<=w;j++)
        {
           if(i==0||j==0)
           dp[i][j]=0;
            else if(a[i]>j)
            {
                dp[i][j]=dp[i-1][j];
            }
            else
            {
                dp[i][j]=max(dp[i-1][j],b[i-1]+dp[i-1][j-a[i-1]]);
            }
        }
    }
    
    cout<<dp[n][w]<<endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:43:19: error: 'W' was not declared in this scope
   43 |     if (n == 0 || W == 0)
      |                   ^
Language: C++

#include<iostream>
#include<algorithm>
int dp(int n,int w,int wt[],int v[])
{
  int d[n+1][w+1];
  for(int i=0;i<=n;i++)
  {
    for(int j=0;j<=w;j++)
    {
      if(i==0||j==0)
        d[i][j]=0;
      else if(wt[i-1]<=j)
        d[i][j]=max(d[i-1][j],v[i-1]+d[i-1][j-wt[i-1]]);
      else
        d[i][j]=d[i-1][j];
    }
  }
    return d[n][w];
}
int main()
{
  int n,w;
  cin>>n>>w;
  int wt[n],v[n];
  for(int i=0;i<n;i++)
    cin>>wt[i]>>v[i];
  cout<<dp(n,w,wt,v)<<endl;  
  return 0;
}

Compiler output:
a.cc: In function 'int dp(int, int, int*, int*)':
a.cc:13:17: error: 'max' was not declared in this scope; did you mean 'std::max'?
   13 |         d[i][j]=max(d[i-1][j],v[i-1]+d[i-1][j-wt[i-1]]);
      |                 ^~~
      |                 std::max
In file included from /usr/include/c++/14/algorithm:61,
                 from a.cc:2:
/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:23:3: error: 'cin' was not declared in this scope; did you mean 'std::cin'?
   23 |   cin>>n>>w;
      |   ^~~
      |   std::cin
In file included 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:27:3: error: 'cout' was not declared in this scope; did you mean 'std::cout'?
   27 |   cout<<dp(n,w,wt,v)<<endl;
      |   ^~~~
      |   std::cout
/usr/include/c++/14/iostream:63:18: note: 'std::cout' declared here
   63 |   extern ostream cout;          ///< Linked to standard output
      |                  ^~~~
a.cc:27:23: error: 'endl' was not declared in this scope; did you mean 'std::endl'?
   27 |   cout<<dp(n,w,wt,v)<<endl;
      |                       ^~~~
      |                       std::endl
In file included from /usr/include/c++/14/iostream:41:
/usr/include/c++/14/ostream:744:5: note: 'std::endl' declared here
  744 |     endl(basic_ostream<_CharT, _Traits>& __os)
      |     ^~~~
Language: C++

#include<stdio>
#include<algorithm>
int dp(int n,int w,int wt[],int v[])
{
  int d[n+1][w+1];
  for(int i=0;i<=n;i++)
  {
    for(int j=0;j<=w;j++)
    {
      if(i==0||j==0)
        d[i][j]=0;
      else if(wt[i-1]<=j)
        d[i][j]=max(d[i-1][j],v[i-1]+d[i-1][j-wt[i-1]]);
      else
        d[i][j]=d[i-1][j];
    }
  }
    return d[n][w];
}
int main()
{
  int n,w;
  cin>>n>>w;
  int wt[n],v[n];
  for(int i=0;i<n;i++)
    cin>>wt[i]>>v[i];
  cout<<dp(n,w,wt,v)<<endl;  
  return 0;
}

Compiler output:
a.cc:1:9: fatal error: stdio: No such file or directory
    1 | #include<stdio>
      |         ^~~~~~~
compilation terminated.
Language: C++

#include<bits/stdc++.h>
int dp(int n,int w,int wt[],int v[])
{
  int d[n+1][w+1];
  for(int i=0;i<=n;i++)
  {
    for(int j=0;j<=w;j++)
    {
      if(i==0||j==0)
        d[i][j]=0;
      else if(wt[i-1]<=j)
        d[i][j]=max(d[i-1][j],v[i-1]+d[i-1][j-wt[i-1]]);
      else
        d[i][j]=d[i-1][j];
    }
  }
    return d[n][w];
}
int main()
{
  int n,w;
  cin>>n>>w;
  int wt[n],v[n];
  for(int i=0;i<n;i++)
    cin>>wt[i]>>v[i];
  cout<<dp(n,w,wt,v)<<endl;  
  return 0;
}

Compiler output:
a.cc: In function 'int dp(int, int, int*, int*)':
a.cc:12:17: error: 'max' was not declared in this scope; did you mean 'std::max'?
   12 |         d[i][j]=max(d[i-1][j],v[i-1]+d[i-1][j-wt[i-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:22:3: error: 'cin' was not declared in this scope; did you mean 'std::cin'?
   22 |   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:26:3: error: 'cout' was not declared in this scope; did you mean 'std::cout'?
   26 |   cout<<dp(n,w,wt,v)<<endl;
      |   ^~~~
      |   std::cout
/usr/include/c++/14/iostream:63:18: note: 'std::cout' declared here
   63 |   extern ostream cout;          ///< Linked to standard output
      |                  ^~~~
a.cc:26:23: error: 'endl' was not declared in this scope; did you mean 'std::endl'?
   26 |   cout<<dp(n,w,wt,v)<<endl;
      |                       ^~~~
      |                       std::endl
In file included from /usr/include/c++/14/istream:41,
                 from /usr/include/c++/14/sstream:40,
                 from /usr/include/c++/14/complex:45,
                 from /usr/include/c++/14/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:127:
/usr/include/c++/14/ostream:744:5: note: 'std::endl' declared here
  744 |     endl(basic_ostream<_CharT, _Traits>& __os)
      |     ^~~~
Language: C

#include<stdio.h> 
  
// A utility function that returns maximum of two integers 
int max(int a, int b) { return (a > b)? a : b; } 
  
// Returns the maximum value that can be put in a knapsack of capacity W 
int knapSack(int W, int wt[], 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;
  scanf("%d %d",&n,&w);
    int val[n]; 
    int wt[n];
  for(int i=0;i<n;i++)
  {
    scanf("%d %d",&wt[i],&val[i]);
  }
    printf("%d", knapSack(W, wt, val, n)); 
    return 0; 
} 

Compiler output:
main.c: In function 'main':
main.c:39:27: error: 'W' undeclared (first use in this function)
   39 |     printf("%d", knapSack(W, wt, val, n));
      |                           ^
main.c:39:27: note: each undeclared identifier is reported only once for each function it appears in
Language: C++

#include <bits/stdc++.h>
using namespace std;
#define clr(arr, x) memset(arr, x, sizeof arr)
#define endl "\n"
#define Accepted 0

const int N = 1e5 + 500;
int n, cap;
vector<pair<long long , long long>> v;
long long Knapsack(int idx, int curcap)
{
	if (idx == n)
		return 0;

	long long ret = Knapsack(idx + 1, curcap);
	if (curcap - v[idx].first >= 0)
		ret = max(ret, v[idx].second + Knapsack(idx + 1, curcap - v[idx].first));

	return ret;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	clr(mem, -1);
	cin >> n >> cap;
	v = vector<pair<long long, long long>>(n);
	for (int i = 0; i < n; i++)
		cin >> v[i].first >> v[i].second;

	cout << Knapsack(0, cap) << endl;
	return Accepted;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:26:13: error: 'mem' was not declared in this scope
   26 |         clr(mem, -1);
      |             ^~~
a.cc:3:28: note: in definition of macro 'clr'
    3 | #define clr(arr, x) memset(arr, x, sizeof arr)
      |                            ^~~
Language: C++

#include<bits/stdc++.h> 
using namespace std;
 
int main()
{
  int i,j,n,p,x=0;
  cin>>n;
  cin>>p;
  int w[n],v[n];
  for(i=0;i<n;i++)
  {
    cin>>w[i];
    cin>>v[i];
  }
  j=0;
  while(j!=n)
  {
    if(w[j]>p)
      j++;
    else
      break;
  }
  for(i=j;i<n;i++)
  {
    x=x+w[i];
    if(x<=p)
    {
      if(i>0)
      	y[i]=y[i-1]+v[i];
      else
       	y[i]=v[0];
    }
    else
    {
      for(k=j;k<i;k++)
      {
        if(v[i]>v[k] && w[i]<w[k])
          y[i]=y[i-1]-v[k]+v[i];
        swap(w[i],w[k]);
        swap(v[i],v[k]);
      }
    }
  }
    cout<<y[n-1]<<endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:29:9: error: 'y' was not declared in this scope
   29 |         y[i]=y[i-1]+v[i];
      |         ^
a.cc:31:9: error: 'y' was not declared in this scope
   31 |         y[i]=v[0];
      |         ^
a.cc:35:11: error: 'k' was not declared in this scope
   35 |       for(k=j;k<i;k++)
      |           ^
a.cc:38:11: error: 'y' was not declared in this scope
   38 |           y[i]=y[i-1]-v[k]+v[i];
      |           ^
a.cc:44:11: error: 'y' was not declared in this scope
   44 |     cout<<y[n-1]<<endl;
      |           ^
Language: C++

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

int main()
{
  int i,j,n,p,x=0;
  cin>>n;
  cin>>p;
  int w[n],v[n];
  for(i=0;i<n;i++)
  {
    cin>>w[i];
    cin>>v[i];
  }
  j=0;
  while(j!=n)
  {
    if(w[j]>p)
      j++;
    else
      break;
  }
  for(i=j;i<n;i++)
  {
    x=x+w[i];
    if(x<=p)
    {
      if(i>0)
      	y[i]=y[i-1]+v[i];
      else
       	y[i]=v[0];
    }
    else
    {
      for(k=j;k<i;k++)
      {
        if(v[i]>v[k] && w[i]<w[k])
          y[i]=y[i-1]-v[k]+v[i];
        swap(w[i],w[k]);
        swap(v[i],v[k]);
      }
    }
  }
    cout<<y[n-1]<<endl;
}
      

Compiler output:
a.cc:1:9: fatal error: bis/stdc++.h: No such file or directory
    1 | #include<bis/stdc++.h>
      |         ^~~~~~~~~~~~~~
compilation terminated.
Language: C++

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

#define ll long long int

ll knapsack(int idx,vector<ll> wt,vector<ll> val,int w,vector<vector<ll>> dp)
{
    if(idx==wt.size()) return 0;

    if(dp[idx][w] != -1) return dp[idx][w];

    if(w - wt[idx] >= 0)
    {
        dp[idx][w] = max(val[idx] + knapsack(idx+1,wt,val,w - wt[idx],dp), knapsack(idx+1,wt,val,w,dp) );
        return dp[idx][w];
    }

    dp[idx][w] = knapsack(idx+1,wt,val,w,dp);
    return dp[idx][w];
}

ll knapsack_2D(vector<ll> wt,vector<ll> val,int w)
{
    int n = wt.size();
    vector<vector<ll>> dp(n+1,vector<ll>(w+1,0));

    for(int i = 1;i <= n;i++ )
    {
        for(int cur_w = 1; cur_w <= w;cur_w++)
        {
            if(cur_w-wt[i-1] >=0)
            {
                dp[i][cur_w] = max(val[i-1] + dp[i-1][cur_w - wt[i-1]], dp[i-1][cur_w]) ;
            }
            else dp[i][cur_w] = dp[i-1][cur_w];
        }
    }

    return dp[n][w];
}

int main() {
    int n,w;
    cin>>n>>w;

    vector<ll> wt(n),val(n);
    for(int i = 0;i<n;i++){
        cin>>wt[i]>>val[i];
    }

    // vector<vector<ll>> dp(n+1,vector<ll>(w+1,-1));
     cout<<knapsack(0,wt,val,w,dp);

   // cout<<knapsack_2D(wt,val,w);
}


Compiler output:
a.cc: In function 'int main()':
a.cc:52:32: error: 'dp' was not declared in this scope; did you mean 'dup'?
   52 |      cout<<knapsack(0,wt,val,w,dp);
      |                                ^~
      |                                dup
Language: C++

#include <bits/stdc++.h>
#include <iostream>
#include <unordered_map>
#include <climits>
using namespace std;
 
typedef long long int lli;
// create a map to store solutions of subproblems
//unordered_map<string, lli> lookup;
vector<lli> lookup(101,-1);
// Values (stored in array v)
// Weights (stored in array w)
// Number of distinct items (n)
// Knapsack capacity W
lli knapSack(vector<int>& w, vector<int>& v, int n, int W)
{
    // base case: Negative capacity
    if (W < 0)
        return INT_MIN;
 	else
    // base case: no items left or capacity becomes 0
    if (n < 0 || W == 0)
        return 0;
 	else
      if (w[n] > W)  lookup[n]= knapSack(w, n-1); 
  	  else{
    	 // assign max value we get by including or excluding current item
        lookup[n] = max (v[n] + knapSack( w,v, n - 1, W - w[n]), knapSack(w,v, n - 1, W));
    }
 
    // return solution to current sub-problem
    return lookup[n];
}
 
// 0-1 Knapsack problem
int main()
{
    int n, W;
	//cin>>n >> W;
	scanf("%d %d", &n, &W);
	vector <int> w(n+1), v(n+1);
	for (int i=0; i<n; ++i){
		scanf("%d %d", &w[i], &v[i]);//cin >>w[i] >>v[i];
	}
 
    lli ans=  knapSack(w,v, n-1 , W);
    printf("%lld\n", ans);
 
    return 0;
}

Compiler output:
a.cc: In function 'lli knapSack(std::vector<int>&, std::vector<int>&, int, int)':
a.cc:25:46: error: invalid initialization of non-const reference of type 'std::vector<int>&' from an rvalue of type 'int'
   25 |       if (w[n] > W)  lookup[n]= knapSack(w, n-1);
      |                                             ~^~
a.cc:15:43: note: in passing argument 2 of 'lli knapSack(std::vector<int>&, std::vector<int>&, int, int)'
   15 | lli knapSack(vector<int>& w, vector<int>& v, int n, int W)
      |                              ~~~~~~~~~~~~~^
Language: C

#include<stdio.h>

using namespace std;
long long max(long long num1, long long num2)
{
    return (num1 > num2 ) ? num1 : num2;
}
int main()
{
   int  n,w,i,j,k;
    scanf("%d %d",&n,&w);
    int  wrr[n];
    long long vrr[n];
    for(k=0;k<n;k++)
    {
        scanf("%d %lld",&wrr[k],&vrr[k]);
    }

   long long T[n+1][w+1];
    for (i = 0; i <= n; i++)
     {
       for (j = 0; j <= w; j++)
       {
           if (i==0 || j==0)
               T[i][j] = 0;
           else if (wrr[i-1] <= j)
                 T[i][j] = max(vrr[i-1] + T[i-1][j-wrr[i-1]],  T[i-1][j]);
           else
                 T[i][j] = T[i-1][j];
       }
     }
  printf("%lld",T[n][w]);


    return 0;
}


Compiler output:
main.c:3:1: error: unknown type name 'using'
    3 | using namespace std;
      | ^~~~~
main.c:3:17: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'std'
    3 | using namespace std;
      |                 ^~~
Language: C++

#define _CRT_SECURE_NO_WARNINGS
/*                   وتزودوا فإن خير الزاد التقوى                    */
/*       وما تدري نفس ماذا تکسب غدا وما تدري نفس باي ارض تموت      */
#include <bits/stdc++.h>
#include<unordered_map>
#include<iomanip>
#include<fstream>
using namespace std;
#include<iostream>
#define endl '\n'
#define ll long long
#define ull unsigned long long
#define dll double
#define PI acos(-1)
#define watch(x) cout<<#x<<" = { "<<x<<" }\n"
#define sz(n) n.size()
#define M_Sayed fast() 
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define RT(v) return cout<<v,0
int dx[] = { 0, 1, 0, -1, 1, 1, -1, -1 };
int dy[] = { 1, 0, -1, 0, 1, -1, 1, -1 };
const double EPS = (1e-7);
ll Ceil(ll x, ll y) { return (x + y - 1) / y; }
void run() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#else
#endif
}
ll gcd(ll a, ll b) { return !b ? abs(a) : gcd(b, a % b); }
ll lcm(ll a, ll b) { return abs(a / gcd(a, b)) * b; }
ll power(ll x, ll y, ll mod) {
	if (y == 0) return 1;
	if (y == 1) return x % mod;
	ll r = power(x, y >> 1, mod);
	return (((r * r) % mod) * power(x, y & 1, mod)) % mod;
}
void fast() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); }
ll n, m, w;
ll vis[111][100099];
vector<ll>v, v2;
ll knapsak(ll x, ll pr)
{
	if (pr==0)
		return 0;
	if (x == n)return 2e9;
	ll ret = 2e9;
	if (vis[x][pr])
		return vis[x][pr];
	vi[x][pr] = 1;
	if (pr >= v2[x]) {
		ret = knapsak(x + 1, pr - v2[x])+v[x];
	}
	ret = min(ret, knapsak(x + 1,  pr));
	vis[x][pr] = ret;
	return ret;
}
int main()
{
	//run();
	M_Sayed;
	cin >> n >> w;
	v.resize(n);
	v2.resize(n);
	for (int i = 0; i < n; i++) {
		cin >> v[i] >> v2[i];
	}
	for (int i = 1e5; i >= 0; i--)
	{
		if (knapsak(0, i) <= w)RT(i);
	}
}

Compiler output:
a.cc: In function 'long long int knapsak(long long int, long long int)':
a.cc:52:9: error: 'vi' was not declared in this scope; did you mean 'vis'?
   52 |         vi[x][pr] = 1;
      |         ^~
      |         vis
Language: Java


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Knapsack {

	static int N, INF = (int) 1e9;
	static Long[][] memo;
	static int[] values;
	static int[] weights;

	
	static Long solve(int idx, int remA) {
		if (remA < 0) 
			return (long) (-1 * INF);
		if (idx == N)
			return 0L;
		if (memo[idx][remA] != -1)
			return memo[idx][remA];
	

	Long	max = Math.max(solve(idx + 1, remA), values[idx] + solve(idx + 1, remA - weights[idx]));

		return memo[idx][remA] = max;
	}

	public static void main(String[] args) throws IOException {
		
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String s = br.readLine();
		StringTokenizer st = new StringTokenizer(s);
		int n = Integer.parseInt(st.nextToken());
		int w = Integer.parseInt(st.nextToken());
		
		memo=new Long [n][w+1];
		N=n;
		for (int i = 0; i < N; i++)
			Arrays.fill(memo[i], -1L);
		values = new int[n];
		weights = new int[n];
		for (int i = 0; i < n; i++) {
			st = new StringTokenizer(br.readLine());
			weights[i] = Integer.parseInt(st.nextToken());
			values[i] = Integer.parseInt(st.nextToken());
		}
		System.out.println(solve(0, w));
	}
}


Compiler output:
Main.java:8: error: class Knapsack is public, should be declared in a file named Knapsack.java
public class Knapsack {
       ^
1 error
Language: C++

#include<bits/stdc++.h>
using namespace std;
struct knap{
	long long int value;
	long long int weight;
};
int main(){
	long long int n,w;
	cin>>n>>w;
	knap arr[n];
	for(int i=0;i<n;i++){
		cin>>arr[i].weight>>arr[i].value;
	}
	sort(arr,arr+n,compare);
	long long int dp[n+1][w+1];
	for(int i=0;i<=n;i++){
		for(int j=0;j<=w;j++){
			if(j<arr[i].weight){
				if(i==0){
					dp[i][j]==0;
				}
				else{
					dp[i][j]=dp[i-1][j];
				}
			}
			else{
				if(i==0){
					dp[i][j]=arr[i].value;
				}
				else{
					dp[i][j]=max(dp[i-1][j],arr[i].value+dp[i-1][j-arr[i].weight]);
				}
			}
		}
	}
	cout<<dp[n][w]<<" ";
}


Compiler output:
a.cc: In function 'int main()':
a.cc:14:24: error: 'compare' was not declared in this scope
   14 |         sort(arr,arr+n,compare);
      |                        ^~~~~~~
Language: Java


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;



	static int N, INF = (int) 1e9;
	static Long[][] memo;
	static int[] values;
	static int[] weights;

	
	static Long solve(int idx, int remA) {
		if (remA < 0) 
			return (long) (-1 * INF);
		if (idx == N)
			return 0L;
		if (memo[idx][remA] != -1)
			return memo[idx][remA];
	

	Long	max = Math.max(solve(idx + 1, remA), values[idx] + solve(idx + 1, remA - weights[idx]));

		return memo[idx][remA] = max;
	}

	public static void main(String[] args) throws IOException {
		
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String s = br.readLine();
		StringTokenizer st = new StringTokenizer(s);
		int n = Integer.parseInt(st.nextToken());
		int w = Integer.parseInt(st.nextToken());
		
		memo=new Long [n][w+1];
		N=n;
		for (int i = 0; i < N; i++)
			Arrays.fill(memo[i], -1L);
		values = new int[n];
		weights = new int[n];
		for (int i = 0; i < n; i++) {
			st = new StringTokenizer(br.readLine());
			weights[i] = Integer.parseInt(st.nextToken());
			values[i] = Integer.parseInt(st.nextToken());
		}
		System.out.println(solve(0, w));
	}



Compiler output:
Main.java:10: error: class, interface, enum, or record expected
	static int N, INF = (int) 1e9;
	       ^
Main.java:11: error: unnamed classes are a preview feature and are disabled by default.
	static Long[][] memo;
	       ^
  (use --enable-preview to enable unnamed classes)
2 errors