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

const int MAX_N = 25; // n????????§???

// ??\???
int n, W;
int w[MAX_N], v[MAX_N];

// i????????\?????????????????????????????????j??\?????????????????????????????¨?????????
// ???????????????????????????????????§??????????????¢??°
int rec(int i, int j) {
  int res;
  if (i == n) {
    // ????????????????????£??????????????¨?????????????????????????????§??????0??§?¢????
    res = 0;
  } else if (j < w[i]) {
    // ???????????????????¶?????????????i?????\????????????????????§?????\?????????????????????????????????
    // i+1 ??\??????????????????????????£?????¨???????????§??????????????????????????´???????????§????????????
    res = rec(i + 1, j);
  } else {
    // ??????i?????\???????????\??????????????????????????§???????????????????????????????????§?????????????????¶
    res = max(rec(i + 1, j),rec(i + 1, j - w[i]) + v[i]);
  }
  return res;
}

void solve() {
  // 0????????\?????§??????W??\????????´?????????????????¨?????????
  cout << rec(0, W) << endl;
}

Compiler output:
a.cc: In function 'int rec(int, int)':
a.cc:20:11: error: 'max' was not declared in this scope
   20 |     res = max(rec(i + 1, j),rec(i + 1, j - w[i]) + v[i]);
      |           ^~~
a.cc: In function 'void solve()':
a.cc:27:3: error: 'cout' was not declared in this scope
   27 |   cout << rec(0, W) << endl;
      |   ^~~~
a.cc:27:24: error: 'endl' was not declared in this scope
   27 |   cout << rec(0, W) << endl;
      |                        ^~~~
Language: C++

#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 25; // n????????§???

// ??\???
int n, W;
int w[MAX_N], v[MAX_N];

// i????????\?????????????????????????????????j??\?????????????????????????????¨?????????
// ???????????????????????????????????§??????????????¢??°
int rec(int i, int j) {
  int res;
  if (i == n) {
    // ????????????????????£??????????????¨?????????????????????????????§??????0??§?¢????
    res = 0;
  } else if (j < w[i]) {
    // ???????????????????¶?????????????i?????\????????????????????§?????\?????????????????????????????????
    // i+1 ??\??????????????????????????£?????¨???????????§??????????????????????????´???????????§????????????
    res = rec(i + 1, j);
  } else {
    // ??????i?????\???????????\??????????????????????????§???????????????????????????????????§?????????????????¶
    res = max(rec(i + 1, j),rec(i + 1, j - w[i]) + v[i]);
  }
  return res;
}

void solve() {
  // 0????????\?????§??????W??\????????´?????????????????¨?????????
  cout << rec(0, W) << endl;
}

Compiler output:
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/14/../../../x86_64-linux-gnu/Scrt1.o: in function `_start':
(.text+0x17): undefined reference to `main'
collect2: error: ld returned 1 exit status
Language: C++

#include <iostream>
#include <algorithm.h>
using namespace std;
int n, W;
int w[100], v[100];
int rec(int i, int j) {
  int res;
  if (i == n) {
    res = 0;
  } else if (j < w[i]) {
    res = rec(i + 1, j);
  } else {
    res = max(rec(i + 1, j),rec(i + 1, j - w[i]) + v[i]);
  }
  return res;
}

int main() {
  cin >> n >> W;
  for(int i=0;i<n;i++){
    cin >> v[i] >> w[i];
  }
  cout << rec(0, W) << endl;
  return 0;
}

Compiler output:
a.cc:2:10: fatal error: algorithm.h: No such file or directory
    2 | #include <algorithm.h>
      |          ^~~~~~~~~~~~~
compilation terminated.
Language: C++

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

struct thing
{
  int w;
  double e;
  int v;
}
  bool cmp(thing t1,thing t2)
  {
    return t1.e<t2.e;
  }
int main()
{
  int W,N,v_sum=0,w_sum=0;
  // vector<int.int,double>w,v;
  // vector<double>e;
  cin>>N>>W;
  thing *t=new thing[N];
  for(int i=0;i<N;i++)
    {
      cin>>t[i].w>>t[i].v;
      t[i].e=(double)t[i].v/t[i].w;
	// cin>>w[i]>>v[i];
	// e[i]=(double)v[i]/w[i];
    }
  e.sort(t,t+N,cmp);
  for(int i=0;i<N&&w_sum<W;i++)
    {
      if(t[i].w<W&&W>w_sum+t[i].w)
	{
	  v_sum+=t[i].v;
	  w_sum+=t[i].w;
	}
    }
  cout<<v_sum<<endl;
}

Compiler output:
a.cc:11:2: error: expected ';' after struct definition
   11 | }
      |  ^
      |  ;
a.cc: In function 'int main()':
a.cc:30:3: error: 'e' was not declared in this scope
   30 |   e.sort(t,t+N,cmp);
      |   ^
Language: C++

#include <iostream>
#include <vector>

using namespace std;

struct Card
{
	int attack;
	int cost;
};



class Solver
{
private:
	vector<Card> cards;
	int card_num; 
	int cost_max;

public:
	Solver(){}

	Solver(vector<Card> cards_, int card_num_, int cost_max_) : cards(cards_), card_num(card_num_), cost_max(cost_max_) {}

	void exec() {
		vector<vector<int> > dp = vector<vector<int> >(card_num + 1, vector<int>(cost_max + 1, 0));
		for (int i = 0; i <= cost_max; ++i)
		{
			dp[0][i] = cards[i].attack;
		}

		for (int i = 1; i < card_num; ++i)
		{
			for (int j = 0; j <= cost_max; ++j)
			{
				if(j - cards[i].cost >= 0) dp[i][j] += dp[i-1][j - cards[i].cost] + cards[i].attack;
			}
		}

		cout << dp[card_num-1][cost_max] << endl;
	}
};




int main(int argc, char *argv[])
{
  	// start from 1 to ignore script name; argv[0] will be a name of processing file.
	for (int i = 1; i < argc; i++) {
		printf ("argv[%i]: %s\n", i, argv[i]);
	}
    int arg_int = 1;
  	int card_num = argv[arg_int];
  	arg_int++;
  	int cost_max = argv[arg_int];
  	arg_int++;

  	vector<Card> cards;
	for (int i = 0; i < card_num; ++i)
	{
		Card tmp_card = {argv[arg_int], argv[arg_int + 1]}
		arg_int += 2;
		cards.push_back(tmp_card);
	}

	cin >> card_num;
	cin >> cost_max;
	for (int i = 0; i < card_num; ++i)
	{
		cin >> cards[i].attack >> cards[i].cost;
	}


	Solver s = Solver(cards, card_num, cost_max);
	s.exec();
	return 0;
}

Compiler output:
a.cc: In function 'int main(int, char**)':
a.cc:55:36: error: invalid conversion from 'char*' to 'int' [-fpermissive]
   55 |         int card_num = argv[arg_int];
      |                        ~~~~~~~~~~~~^
      |                                    |
      |                                    char*
a.cc:57:36: error: invalid conversion from 'char*' to 'int' [-fpermissive]
   57 |         int cost_max = argv[arg_int];
      |                        ~~~~~~~~~~~~^
      |                                    |
      |                                    char*
a.cc:63:46: error: invalid conversion from 'char*' to 'int' [-fpermissive]
   63 |                 Card tmp_card = {argv[arg_int], argv[arg_int + 1]}
      |                                  ~~~~~~~~~~~~^
      |                                              |
      |                                              char*
a.cc:63:65: error: invalid conversion from 'char*' to 'int' [-fpermissive]
   63 |                 Card tmp_card = {argv[arg_int], argv[arg_int + 1]}
      |                                                 ~~~~~~~~~~~~~~~~^
      |                                                                 |
      |                                                                 char*
a.cc:64:17: error: expected ',' or ';' before 'arg_int'
   64 |                 arg_int += 2;
      |                 ^~~~~~~
Language: C++

#include<iostream>
#include<algorithm>

using namespace std;

int n, W;
int weight[110], value[110];

int dp[110][1010];

int main()
{
    cin >> n;
    for(int i = 0; i < n; i++)
        cin >> weight[i] >> value[i];

    for(int w = 0; w <= W; w++)
        dp[0][W] = 0;

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

    cout << dp[n][w] << endl;
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:29:19: error: 'w' was not declared in this scope
   29 |     cout << dp[n][w] << endl;
      |                   ^
Language: C++

#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;
const int INF = 1 << 30;
const int maxx = 10010;

int dp[maxx], s[maxx];
int w[maxx], v[maxx];
int main() {
	int n, W;
	int A[100];
	int T[50000 + 10];
	scanf("%d %d", &n, &W);
	memset(dp, 0, sizeof(dp));
	memset(s, 0, sizeof(s));
	for (int i = 1; i <= n; i++)
	{
		scanf("%d %d", &v[i], &w[i]);
		s[i] = s[i - 1] + w[i];
	}
	for (int i = 1; i <= n; i++)
	{
		int b = max(w[i], W - s[n] + s[i - 1]);
		for (int j = W; j >= b; j--)
			dp[j] = max(dp[j], dp[j - w[i]] + v[i]);
	}
	printf("%d\n", dp[W]);
	return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:15:9: error: 'memset' was not declared in this scope
   15 |         memset(dp, 0, sizeof(dp));
      |         ^~~~~~
a.cc:4:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
    3 | #include <cstdio>
  +++ |+#include <cstring>
    4 | using namespace std;
Language: C++

#include<iostream>
#include<vector>
#include<algorithm>
#define NMAX 105
#define WMAX 10005
#define DIAGONAL 1
#define TOP 0

using namespace std;

struct Item {
  int value, weight;
};

int N, W;
Item items[NMAX + 1];
int C[NMAX + 1][WMAX + 1], G[NMAX + 1][WMAX + 1];

void compute(int &maxValue, vector<int> &selection) {
  for ( int w = 0; w <= Wl w++ ) {
    C[0][w] = 0;
    G[0][w] = DIAGONAL;
  }

  for ( int i = 1; i <= N; i++ ) C[i][o] = 0;

  for ( int i = 1; i <= N; i++ )
    for ( int w = 1; w <= W; w++ ) {
      C[i][w] = C[i - 1][w];
      G[i][w] = TOP;
      if ( items[i].weight > w ) continue;
      if ( items[i].value + C[i - 1][w - items[i].weight] > C[i - 1][w] ) {
        C[i][w] = items[i].value + C[i - 1][w - items[i].weight];
        G[i][w] = DIAGONAL;
      }
    }

  maxValue = C[N][W];
  selection.clear();
  for ( int i = N, w = W; i >= 1; i-- )
    if ( G[i][w] == DIAGONAL ) {
      selection.push_back(i);
      w -= items[i].weight;
    }

  reverse(selection.begin(), selection.end());
}

void input() {
  cin >> N >> W;
  for ( int i = 1; i <= N; i++ )
    cin >> items[i].value >> items[i].weight;
}

int main() {
  int maxValue;
  vector<int> selection;
  input();
  compute(maxValue, selection);

  cout << maxValue << endl;

  return 0;
}


Compiler output:
a.cc: In function 'void compute(int&, std::vector<int>&)':
a.cc:20:25: error: 'Wl' was not declared in this scope; did you mean 'W'?
   20 |   for ( int w = 0; w <= Wl w++ ) {
      |                         ^~
      |                         W
a.cc:20:27: error: expected ';' before 'w'
   20 |   for ( int w = 0; w <= Wl w++ ) {
      |                           ^~
      |                           ;
a.cc:25:39: error: 'o' was not declared in this scope
   25 |   for ( int i = 1; i <= N; i++ ) C[i][o] = 0;
      |                                       ^
Language: C++

#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;

typedef long long ll;

#define min(a, b) (((a) < (b))? (a):(b))
#define max(a, b) (((a) > (b))? (a):(b))
#define REP(i, a, n) for(int i=(a); i<(n); i++)
#define rep(i, n) REP(i, 0, (n))
#define square(a) (a)*(a)
#define pb push_back

int n,W;
int weight[110],value[110];

int dp[110][10010];

int main(){
    cin >> n >> W;
    rep(i,n) cin >> value[i] >> weight[i];
    
    rep(w,W) dp[0][w] = 0;
    
    rep(i,n){
        for (int w = 0; w <= W; ++w){
            if (w >= weight[i]) dp[i+1][w] = max(dp[i][w-weight[i]] + value[i] , dp[i][w]);
            else dp[i+1][w] = dp[i][w];
        }
    }
    cout << dp[n][w] << endl;
}



Compiler output:
a.cc: In function 'int main()':
a.cc:33:19: error: 'w' was not declared in this scope
   33 |     cout << dp[n][w] << endl;
      |                   ^
Language: C++

#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <utility>
#include <functional>
#include <deque>
#include <cctype>
#include <stack>
#include <bitset>

using ll = long long;
typedef unsigned long long ull;
typedef std::pair<ll, ll>P;

ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

const ll mod = 1000000007;
const ll INF = 1 << 30;
const ll INF2 = 8000000000000000000LL;
bool fl = true;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
std::string abc = "abcdefghijklmnopqrstuvwxyz";
struct edge { ll to, cost; };
struct edge1 { ll from, to, cost; };
double pai = 3.141592653589793;
int n, v[1010], w[1010], s, dp[1010][1010];

int rec(int i, int j) {
	if (dp[i][j] != -1)return dp[i][j];
	int res;
	if (i == n)res = 0;
	else if (j < w[i])res = rec(i + 1, j);
	else res = std::max(rec(i + 1, j), rec(i + 1, j - w[i]) + v[i]);
	return dp[i][j] = res;
}

int main() {
	std::cin >> n >> s;
	for (int i = 0;i < n;i++) {
		std::cin >> v[i] >> w[i];
	}
	std::memset(dp, -1, sizeof(dp));
	std::cout << rec(0, s) << std::endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:54:14: error: 'memset' is not a member of 'std'; did you mean 'wmemset'?
   54 |         std::memset(dp, -1, sizeof(dp));
      |              ^~~~~~
      |              wmemset
Language: C++

#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<set>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int MAX_N=100000;
const int INF = 0x3f3f3f3f;

struct item{
	int value;
	int weight;
};
int n,W;
item items[106];
int c[106][10006];
int g[106][10006];

void compute(int &maxvalue,vector<int> &selection){
	for(int q=0;q<=W;q++){
		c[0][q]=0;
		g[0][q]=1;
	}
	
	for(int i=1;i<=n;i++)
		c[i][0]=0;
		
	for(int i=1;i<=n;i++){
		for(int w=1;w<=W;w++){
			dp[i][w]=dp[i-1][w];
			g[i][w]=0;
			if(items[i].weight>w)
				continue;
			if(items[i].value+c[i-1][w-items[i].weight]>c[i-1][w]){
				c[i][w]=items[i].value+c[i-1][w-items[i].weight];
				g[i][w]=1;
			}
		}
	}
	
	maxvalue=c[n][W];
	selection.clear();
	for(int i=n,w=W;i>=1;i--){
		if(g[i][w]==1){
			selection.push_back(i);
			w=w-items[i].weight;
		}
	}
	
	reverse(selection.begin(),selection.end());/*
	vector<int>::iterator a=selection.begin();
	for(;a!=selection.end();a++){
		cout<<*a<<endl;
	}*/
}
int main(){
	ios::sync_with_stdio(false);
	int maxvalue;
	vector<int> selection;
	cin>>n>>W;
	for(int i=1;i<=n;i++){
		cin>>items[i].value>>items[i].weight;
	}
	compute(maxvalue,selection);
	cout<<maxvalue<<endl;

	return 0;
}




Compiler output:
a.cc: In function 'void compute(int&, std::vector<int>&)':
a.cc:37:25: error: 'dp' was not declared in this scope
   37 |                         dp[i][w]=dp[i-1][w];
      |                         ^~
Language: C++

#include<stdio.h>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <iterator>
#include <list>
#include <map>     
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <iomanip>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define ll long long
#define ld long double
#define rep(a,t) for(int a=0;a<t;a++) 
#define forever while(true)
#define Sort(a) sort(a.begin(),a.end())
#define Reverse(a) reverse(a.begin(),a.end())
#define pb push_back
int n, maxw;
int ret = 0;
vector<int>vs,ws;

void knapsack(int cnt, int w, int v) {
	if (w > maxw) {
		return; 
	}
	ret = max(ret, v);
	if (cnt >= n) {
		return;
	}
	knapsack(cnt + 1, w, v);
	knapsack(cnt + 1, w+ws[cnt], v+vs[cnt]);
}
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	cin >> n >> maxw;
	vs.clear();
	rep(i, n) {
		int v1, w1;
		vs.pb(v1);
		ws.pb(w1);
	}
	knapsack(0,0,0);
	cout << ret << endl;
	return 0;
}


Compiler output:
a.cc: In function 'void knapsack(int, int, int)':
a.cc:45:29: error: reference to 'ws' is ambiguous
   45 |         knapsack(cnt + 1, w+ws[cnt], v+vs[cnt]);
      |                             ^~
In file included from /usr/include/c++/14/istream:1109,
                 from /usr/include/c++/14/sstream:40,
                 from /usr/include/c++/14/complex:45,
                 from a.cc:7:
/usr/include/c++/14/bits/istream.tcc:1073:5: note: candidates are: 'template<class _CharT, class _Traits> std::basic_istream<_CharT, _Traits>& std::ws(basic_istream<_CharT, _Traits>&)'
 1073 |     ws(basic_istream<_CharT, _Traits>& __in)
      |     ^~
a.cc:34:15: note:                 'std::vector<int> ws'
   34 | vector<int>vs,ws;
      |               ^~
a.cc: In function 'int main()':
a.cc:57:17: error: reference to 'ws' is ambiguous
   57 |                 ws.pb(w1);
      |                 ^~
/usr/include/c++/14/bits/istream.tcc:1073:5: note: candidates are: 'template<class _CharT, class _Traits> std::basic_istream<_CharT, _Traits>& std::ws(basic_istream<_CharT, _Traits>&)'
 1073 |     ws(basic_istream<_CharT, _Traits>& __in)
      |     ^~
a.cc:34:15: note:                 'std::vector<int> ws'
   34 | vector<int>vs,ws;
      |               ^~
Language: C++

#define max_i 100
#define max_j 10000
int dp[max_i][max_j];

void solve(){
  int n,m;
  int v[max_i+1],w[max_i+1];

  std::cin >> n>>m;
  for (int i = 0; i < n; i++) {
    /* code */
    std::cin >> v[i]>>w[i];
  }
  for (int i = 0; i < n; i++) {
    for(int j = 0;j<=m;j++){
      if(j<w[i]){
        dp[i+1][j] = dp[i][j];
      }else{
        dp[i+1][j] = max(dp[i][j-w[i]]+v[i],dp[i][j]);
      }
    }
  }

  std::cout << dp[n][m] << '\n';
}

int main(){
  solve();
return 0;
}



Compiler output:
a.cc: In function 'void solve()':
a.cc:9:8: error: 'cin' is not a member of 'std'
    9 |   std::cin >> n>>m;
      |        ^~~
a.cc:1:1: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
  +++ |+#include <iostream>
    1 | #define max_i 100
a.cc:12:10: error: 'cin' is not a member of 'std'
   12 |     std::cin >> v[i]>>w[i];
      |          ^~~
a.cc:12:10: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:19:22: error: 'max' was not declared in this scope
   19 |         dp[i+1][j] = max(dp[i][j-w[i]]+v[i],dp[i][j]);
      |                      ^~~
a.cc:24:8: error: 'cout' is not a member of 'std'
   24 |   std::cout << dp[n][m] << '\n';
      |        ^~~~
a.cc:24:8: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
Language: C++

#include <iostream>
using namespace std;
int n,W;
int dp[101][10001];
int v[101],w[101];

int solve(int i,int j){
	if(dp[i][j]>0) return dp[i][j];
	int res;
	if(i==n){
		res=0;
	}else if(w[i]> j){
		res=solve(i+1,j);
	}else{
		res=max(solve(i+1,j),solve(i+1,j-w[i])+v[i]);
	}
	return dp[i][j]=res;
}

int main(void){
	cin>>n>>W;
	for(int i=0;i< n ;i++){
		cin>>v[i]>>w[i];
	}
	memset(dp,-1,sizeof(dp));
	
	cout<<solve(0,W)<<endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:25:9: error: 'memset' was not declared in this scope
   25 |         memset(dp,-1,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 | using namespace std;
Language: C++

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



  int search(int n,int w){
    int c=0;
    if(w==0){return 0;}
    if(n==0){
      if(w-b[0]>=0){return a[0];}
      else{return 0;}
    }
    if(w-b[n]>=0){c=a[n]+search(n-1,w-b[n]);}
    c=max(c,search(n-1,w));
    return c;
  }


int main(){
  int n,w;
  cin>>n>>w;
  int a[10001],b[10001];
  for(int i=0;i<n;i++){
    cin>>a[i]>>b[i];
  }

  cout<<search(n-1,w)<<endl;



  return 0;
  }



Compiler output:
a.cc: In function 'int search(int, int)':
a.cc:10:12: error: 'b' was not declared in this scope
   10 |       if(w-b[0]>=0){return a[0];}
      |            ^
a.cc:10:28: error: 'a' was not declared in this scope
   10 |       if(w-b[0]>=0){return a[0];}
      |                            ^
a.cc:13:10: error: 'b' was not declared in this scope
   13 |     if(w-b[n]>=0){c=a[n]+search(n-1,w-b[n]);}
      |          ^
a.cc:13:21: error: 'a' was not declared in this scope
   13 |     if(w-b[n]>=0){c=a[n]+search(n-1,w-b[n]);}
      |                     ^
Language: C++

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#pragma comment(linker,"/STACK:102400000,102400000")
#define inf 0x3f3f3f3f
#define mem(x,t) memset(x,t,sizeof(x));
#define maxm 100000
typedef long long ll;
using namespace std;
struct item0
{
    int v,w;
}item[maxm];
int main()
{
    ios::sync_with_stdio(false);
    int n,w;
    cin>>n>>w;
    for(int i=1;i<=n;i++)
        cin>>item[i].v>>item[i].w;
    int c[maxm];
    memset(c,0,sizeof(c));
    for(int i=1;i<=n;i++)
    {
        for(int j=item[i].w;j<=w;j++)
        {
            c[j]=max(c[j-item[i].w]+item[i].v /*取这个物品*/, c[j] /*不取这个物品*/);
        }
    }
    cout<<c[w]<<endl;
    return 0;
}



Compiler output:
a.cc: In function 'int main()':
a.cc:27:5: error: 'memset' was not declared in this scope
   27 |     memset(c,0,sizeof(c));
      |     ^~~~~~
a.cc:9:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
    8 | #include <vector>
  +++ |+#include <cstring>
    9 | #pragma comment(linker,"/STACK:102400000,102400000")
Language: C++

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#pragma comment(linker,"/STACK:102400000,102400000")
#define inf 0x3f3f3f3f
#define mem(x,t) memset(x,t,sizeof(x));
#define maxm 100000
typedef long long ll;
using namespace std;
struct item0
{
    int v,w;
}item[maxm];
int main()
{
    ios::sync_with_stdio(false);
    int n,w;
    cin>>n>>w;
    for(int i=1;i<=n;i++)
        cin>>item[i].v>>item[i].w;
    int c[maxm];
    memset(c,0,sizeof(c));
    for(int i=1;i<=n;i++)
    {
        for(int j=item[i].w;j<=w;j++)
        {
            c[j]=max(c[j-item[i].w]+item[i].v,c[j]);
        }
    }
    cout<<c[w]<<endl;
    return 0;
}



Compiler output:
a.cc: In function 'int main()':
a.cc:27:5: error: 'memset' was not declared in this scope
   27 |     memset(c,0,sizeof(c));
      |     ^~~~~~
a.cc:9:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
    8 | #include <vector>
  +++ |+#include <cstring>
    9 | #pragma comment(linker,"/STACK:102400000,102400000")
Language: C++

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#pragma comment(linker,"/STACK:102400000,102400000")
#define inf 0x3f3f3f3f
#define mem(x,t) memset(x,t,sizeof(x));
#define maxm 10000
typedef long long ll;
using namespace std;
struct item0
{
    int v,w;
}item[maxm];
int main()
{
    ios::sync_with_stdio(false);
    int n,w;
    cin>>n>>w;
    for(int i=1;i<=n;i++)
        cin>>item[i].v>>item[i].w;
    int c[maxm];
    memset(c,0,sizeof(c));
    for(int i=1;i<=n;i++)
    {
        for(int j=item[i].w;j<=w;j++)
        {
            c[j]=max(c[j-item[i].w]+item[i].v,c[j]);
        }
    }
    cout<<c[w]<<endl;
    return 0;
}



Compiler output:
a.cc: In function 'int main()':
a.cc:27:5: error: 'memset' was not declared in this scope
   27 |     memset(c,0,sizeof(c));
      |     ^~~~~~
a.cc:9:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
    8 | #include <vector>
  +++ |+#include <cstring>
    9 | #pragma comment(linker,"/STACK:102400000,102400000")
Language: C++

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#pragma comment(linker,"/STACK:102400000,102400000")
#define inf 0x3f3f3f3f
#define maxm 100000
typedef long long ll;
using namespace std;
int main()
{
    int v[maxm],w[maxm];
    int f[maxm];
    memset(f,0,sizeof(f));
    int N,W;
    cin>>N>>W;
    for(int i=1;i<=N;i++)
        scanf("%d%d",&v[i],&w[i]);
    for(int i=1;i<=N;i++)
    {
        for(int j=W;j>=w[i];j--)
        {
            f[j]=max(f[j],f[j-w[i]]+v[i]);
        }
    }
    cout<<f[W]<<endl;
}



Compiler output:
a.cc: In function 'int main()':
a.cc:18:5: error: 'memset' was not declared in this scope
   18 |     memset(f,0,sizeof(f));
      |     ^~~~~~
a.cc:9:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
    8 | #include <vector>
  +++ |+#include <cstring>
    9 | #pragma comment(linker,"/STACK:102400000,102400000")
Language: C++

import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Main main=new Main();
		main.run();
	}

	void run() {
		
		Scanner sc=new Scanner(System.in);
		
		int N=sc.nextInt();
		int W=sc.nextInt();
		
		int[] value=new int[N];
		int[] weight=new int[N];
		
		for(int i=0;i<N;i++) {
			value[i]=sc.nextInt();
			weight[i]=sc.nextInt();
		}
		
		//dp[i][w]=i番目までのアイテムと重さwのリュックを使った時の価値の最大値
		//dp[0][0]=0;
		
		int[][] dp= new int[N+1][W+1];//0オリジンだから、要素の数はN+1,W+1
		
		//アイテムを一つも使わなければ、価値は0
		for(int w=0;w<W+1;w++) {
			dp[0][w]=0;
		}
		
		
		for(int i=0;i<N;i++) {
			
			for(int w=0;w<W+1;w++) {
				
				//そもそも入る余地があるのかどうか
				if(w>=weight[i]) {
					dp[i+1][w]=Math.max(dp[i][w-weight[i]]+value[i],dp[i][w]);
				}else {
					dp[i+1][w]=dp[i][w];
				}
				
			}
			
		}
		
		System.out.println(dp[N+1][W+1]);
		
		sc.close();
		
		
	}
}






Compiler output:
a.cc:1:1: error: 'import' does not name a type
    1 | import java.util.ArrayDeque;
      | ^~~~~~
a.cc:1:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:2:1: error: 'import' does not name a type
    2 | import java.util.Deque;
      | ^~~~~~
a.cc:2:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:3:1: error: 'import' does not name a type
    3 | import java.util.Scanner;
      | ^~~~~~
a.cc:3:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:5:1: error: expected unqualified-id before 'public'
    5 | public class Main{
      | ^~~~~~
Language: C++

#include <iostream>
#include <vector>
#include <map>
using namespace std;

int main(void) {

    int N, W; cin >> N >> W;
    vector<int> v(N), w(N);
    for (int i = 0; i < N; i++) cin >> v[i] >> w[i];

    int BEAM = 100;
    vector<pair<int, int>> curr;
    curr.emplace_back(0, 0);

    for (int i = 0; i < N; i++) {
        vector<pair<int,int>> next;
        for (const auto& s: curr) {
            next.emplace_back(s);
            if (s.second + w[i] <= W) {
                next.emplace_back(s.first+v[i], s.second+w[i]);
            }
        }
        sort(next.rbegin(), next.rend());
        if (next.size() > BEAM) next.resize(BEAM);
        curr = move(next);
    }

    cout << curr[0].first << endl;

    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:24:9: error: 'sort' was not declared in this scope; did you mean 'short'?
   24 |         sort(next.rbegin(), next.rend());
      |         ^~~~
      |         short
Language: C++

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

int main(){
    int N,W; cin>>N>>W;
    int v[N],w[N];
    for(int i=0;i<N;i++){
        cin>>v[i]>>w[i];
    }
    int dp[110][10010];
    for(int i=0;i<=W;i++) dp[0][i]=0;

    for(int i=0;i<N;i++){
        for(int j=0;j<=W;j++){
            if(w >= w[i]) dp[i+1][w] = max(dp[i][w-w[i]]+v[i], dp[i][w]);
            else dp[i+1][w] = dp[i][w];
        }
    }

    
    cout<<dp[N][W]<<endl;
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:15:18: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
   15 |             if(w >= w[i]) dp[i+1][w] = max(dp[i][w-w[i]]+v[i], dp[i][w]);
      |                ~~^~~~~~~
a.cc:15:34: error: invalid types 'int [10010][int [N]]' for array subscript
   15 |             if(w >= w[i]) dp[i+1][w] = max(dp[i][w-w[i]]+v[i], dp[i][w]);
      |                                  ^
a.cc:15:49: error: invalid types 'int [10010][int*]' for array subscript
   15 |             if(w >= w[i]) dp[i+1][w] = max(dp[i][w-w[i]]+v[i], dp[i][w]);
      |                                                 ^
a.cc:15:69: error: invalid types 'int [10010][int [N]]' for array subscript
   15 |             if(w >= w[i]) dp[i+1][w] = max(dp[i][w-w[i]]+v[i], dp[i][w]);
      |                                                                     ^
a.cc:16:25: error: invalid types 'int [10010][int [N]]' for array subscript
   16 |             else dp[i+1][w] = dp[i][w];
      |                         ^
a.cc:16:36: error: invalid types 'int [10010][int [N]]' for array subscript
   16 |             else dp[i+1][w] = dp[i][w];
      |                                    ^
Language: C++


#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

#define NMAX 105
#define WMAX 10005;
#define DIAGONAL 1
#define TOP 0

struct Item {
  int value, weight;
};

int N, W;
Item items[NMAX + 1];
int C[NMAX + 1][WMAX + 1], C[NMAX + 1][WMAX + 1];

void compute(int& maxValue, vector<int>& selection) {
  for (int w = 0; w <= W; w++) {
    C[0][w] = 0;
    G[0][w] = DIAGONAL;
  }

  for (int i = 0; i <= N; i++) {
    C[i][0] = 0;
  }

  for (int i = 1; i <= N; i++) {
    for (int w = 1; w <= W; w++) {
      C[i][w] = C[i - 1][W];
      G[i][w] = TOP;
      if (items[i].weight > w) {
        continue;
      }
      if (items[i].value + C[i - 1][w - items[i].weight] > C[i - 1][w]) {
        C[i][w] = items[i].value + C[i - 1][w - items[i].weight];
        G[i][w] = DIAGONAL;
      }
    }
  }

  maxValue = C[N][W];
  selection.clear();
  for (int i = N, w = W; i >= 1; i--) {
    if (G[i][w] == DIAGONAL) {
      selection.push_back(i);
      w -= items[i].weight;
    }
  }

  reverse(selection.begin(), selection.end());
}

void input() {
  cin >> N >> W;
  for (int i = 1; i <= N; i++) {
    cin >> items[i].value >> items[i].weight;
  }
}

int main() {
  int maxValue;
  vector<int> selection;

  input();
  compute(maxValue, selection);

  cout << maxValue << endl;

  return 0;
}


Compiler output:
a.cc:9:19: error: expected ']' before ';' token
    9 | #define WMAX 10005;
      |                   ^
a.cc:19:17: note: in expansion of macro 'WMAX'
   19 | int C[NMAX + 1][WMAX + 1], C[NMAX + 1][WMAX + 1];
      |                 ^~~~
a.cc:19:22: error: expected unqualified-id before '+' token
   19 | int C[NMAX + 1][WMAX + 1], C[NMAX + 1][WMAX + 1];
      |                      ^
a.cc:19:45: error: expected unqualified-id before '+' token
   19 | int C[NMAX + 1][WMAX + 1], C[NMAX + 1][WMAX + 1];
      |                                             ^
a.cc: In function 'void compute(int&, std::vector<int>&)':
a.cc:23:5: error: 'C' was not declared in this scope
   23 |     C[0][w] = 0;
      |     ^
a.cc:24:5: error: 'G' was not declared in this scope
   24 |     G[0][w] = DIAGONAL;
      |     ^
a.cc:28:5: error: 'C' was not declared in this scope
   28 |     C[i][0] = 0;
      |     ^
a.cc:33:7: error: 'C' was not declared in this scope
   33 |       C[i][w] = C[i - 1][W];
      |       ^
a.cc:34:7: error: 'G' was not declared in this scope
   34 |       G[i][w] = TOP;
      |       ^
a.cc:45:14: error: 'C' was not declared in this scope
   45 |   maxValue = C[N][W];
      |              ^
a.cc:48:9: error: 'G' was not declared in this scope
   48 |     if (G[i][w] == DIAGONAL) {
      |         ^
Language: C++


#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

#define NMAX 105
#define WMAX 10005
#define DIAGONAL 1
#define TOP 0

struct Item {
  int value, weight;
};

int N, W;
Item items[NMAX + 1];
int C[NMAX + 1][WMAX + 1], C[NMAX + 1][WMAX + 1];

void compute(int& maxValue, vector<int>& selection) {
  for (int w = 0; w <= W; w++) {
    C[0][w] = 0;
    G[0][w] = DIAGONAL;
  }

  for (int i = 0; i <= N; i++) {
    C[i][0] = 0;
  }

  for (int i = 1; i <= N; i++) {
    for (int w = 1; w <= W; w++) {
      C[i][w] = C[i - 1][W];
      G[i][w] = TOP;
      if (items[i].weight > w) {
        continue;
      }
      if (items[i].value + C[i - 1][w - items[i].weight] > C[i - 1][w]) {
        C[i][w] = items[i].value + C[i - 1][w - items[i].weight];
        G[i][w] = DIAGONAL;
      }
    }
  }

  maxValue = C[N][W];
  selection.clear();
  for (int i = N, w = W; i >= 1; i--) {
    if (G[i][w] == DIAGONAL) {
      selection.push_back(i);
      w -= items[i].weight;
    }
  }

  reverse(selection.begin(), selection.end());
}

void input() {
  cin >> N >> W;
  for (int i = 1; i <= N; i++) {
    cin >> items[i].value >> items[i].weight;
  }
}

int main() {
  int maxValue;
  vector<int> selection;

  input();
  compute(maxValue, selection);

  cout << maxValue << endl;

  return 0;
}


Compiler output:
a.cc:19:28: error: redefinition of 'int C [106][10006]'
   19 | int C[NMAX + 1][WMAX + 1], C[NMAX + 1][WMAX + 1];
      |                            ^
a.cc:19:5: note: 'int C [106][10006]' previously declared here
   19 | int C[NMAX + 1][WMAX + 1], C[NMAX + 1][WMAX + 1];
      |     ^
a.cc: In function 'void compute(int&, std::vector<int>&)':
a.cc:24:5: error: 'G' was not declared in this scope
   24 |     G[0][w] = DIAGONAL;
      |     ^
a.cc:34:7: error: 'G' was not declared in this scope
   34 |       G[i][w] = TOP;
      |       ^
a.cc:48:9: error: 'G' was not declared in this scope
   48 |     if (G[i][w] == DIAGONAL) {
      |         ^
Language: C++

/*
 * Contents   : AOJ DPL 1 B
 * Author     : KitauraHiromi
 * LastUpdate : 20180610
 * Since      : 20180610
 */
#include <iostream>
#include <vector>
int N, W;
int dp[101][1001]; // valueを保持
int value[101], weight[101];
int main(void){
    cin >> N >> W;
    memset(dp, 0, sizeof(dp));
    for(int i=0; i<N; ++i) cin >> value[i] >> weight[i];
    for(int i=0; i<N-1; ++i){
        for(int w=0; w<W; ++w){
            (w < W) ? dp[i+1][w] = max(dp[i][w-weight[i]] + value[i], dp[i][w]) : dp[i][w];
        }
    }
    cout << dp[N][W] << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:13:5: error: 'cin' was not declared in this scope; did you mean 'std::cin'?
   13 |     cin >> N >> W;
      |     ^~~
      |     std::cin
In file included from a.cc:7:
/usr/include/c++/14/iostream:62:18: note: 'std::cin' declared here
   62 |   extern istream cin;           ///< Linked to standard input
      |                  ^~~
a.cc:14:5: error: 'memset' was not declared in this scope
   14 |     memset(dp, 0, sizeof(dp));
      |     ^~~~~~
a.cc:9:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
    8 | #include <vector>
  +++ |+#include <cstring>
    9 | int N, W;
a.cc:18:36: error: 'max' was not declared in this scope; did you mean 'std::max'?
   18 |             (w < W) ? dp[i+1][w] = max(dp[i][w-weight[i]] + value[i], dp[i][w]) : dp[i][w];
      |                                    ^~~
      |                                    std::max
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:
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: 'std::max' declared here
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
a.cc:21:5: error: 'cout' was not declared in this scope; did you mean 'std::cout'?
   21 |     cout << dp[N][W] << 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:21:25: error: 'endl' was not declared in this scope; did you mean 'std::endl'?
   21 |     cout << dp[N][W] << endl;
      |                         ^~~~
      |                         std::endl
/usr/include/c++/14/ostream:744:5: note: 'std::endl' declared here
  744 |     endl(basic_ostream<_CharT, _Traits>& __os)
      |     ^~~~
Language: C++

/*
 * Contents   : AOJ DPL 1 B
 * Author     : KitauraHiromi
 * LastUpdate : 20180610
 * Since      : 20180610
 */
#include <iostream>
#include <vector>
using namespace std;
int N, W;
int dp[101][1001]; // valueを保持
int value[101], weight[101];
int main(void){
    cin >> N >> W;
    memset(dp, 0, sizeof(dp));
    for(int i=0; i<N; ++i) cin >> value[i] >> weight[i];
    for(int i=0; i<N-1; ++i){
        for(int w=0; w<W; ++w){
            (w < W) ? dp[i+1][w] = max(dp[i][w-weight[i]] + value[i], dp[i][w]) : dp[i][w];
        }
    }
    cout << dp[N][W] << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:15:5: error: 'memset' was not declared in this scope
   15 |     memset(dp, 0, sizeof(dp));
      |     ^~~~~~
a.cc:9:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
    8 | #include <vector>
  +++ |+#include <cstring>
    9 | using namespace std;
Language: C++

/*
 * Contents   : AOJ DPL 1 B
 * Author     : KitauraHiromi
 * LastUpdate : 20180610
 * Since      : 20180610
 */
#include <iostream>
#include <math>
using namespace std;
int N, W;
int dp[101][1001]; // valueを保持
int value[101], weight[101];
int main(void){
    cin >> N >> W;
    memset(dp, 0, sizeof(dp));
    for(int i=0; i<N; ++i) cin >> value[i] >> weight[i];
    for(int i=0; i<N-1; ++i){
        for(int w=0; w<W; ++w){
            (w < W) ? dp[i+1][w] = max(dp[i][w-weight[i]] + value[i], dp[i][w]) : dp[i+1][w] = dp[i][w];
        }
    }
    cout << dp[N][W] << endl;
}


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

/*
 * Contents   : AOJ DPL 1 B
 * Author     : KitauraHiromi
 * LastUpdate : 20180610
 * Since      : 20180610
 */
#include <iostream>
#include <math.h>
using namespace std;
int N, W;
int dp[101][1001]; // valueを保持
int value[101], weight[101];
int main(void){
    cin >> N >> W;
    memset(dp, 0, sizeof(dp));
    for(int i=0; i<N; ++i) cin >> value[i] >> weight[i];
    for(int i=0; i<N-1; ++i){
        for(int w=0; w<W; ++w){
            (w < W) ? dp[i+1][w] = max(dp[i][w-weight[i]] + value[i], dp[i][w]) : dp[i+1][w] = dp[i][w];
        }
    }
    cout << dp[N][W] << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:15:5: error: 'memset' was not declared in this scope
   15 |     memset(dp, 0, sizeof(dp));
      |     ^~~~~~
a.cc:9:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
    8 | #include <math.h>
  +++ |+#include <cstring>
    9 | using namespace std;
Language: C++

/*
 * Contents   : AOJ DPL 1 B
 * Author     : KitauraHiromi
 * LastUpdate : 20180610
 * Since      : 20180610
 */
#include <iostream>
#include <cmath>
using namespace std;
int N, W;
int dp[101][1001]; // valueを保持
int value[101], weight[101];
int main(void){
    cin >> N >> W;
    memset(dp, 0, sizeof(dp));
    for(int i=0; i<N; ++i) cin >> value[i] >> weight[i];
    for(int i=0; i<N-1; ++i){
        for(int w=0; w<W; ++w){
            (w < W) ? dp[i+1][w] = max(dp[i][w-weight[i]] + value[i], dp[i][w]) : dp[i+1][w] = dp[i][w];
        }
    }
    cout << dp[N][W] << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:15:5: error: 'memset' was not declared in this scope
   15 |     memset(dp, 0, sizeof(dp));
      |     ^~~~~~
a.cc:9:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
    8 | #include <cmath>
  +++ |+#include <cstring>
    9 | using namespace std;
Language: C++

N, W = map(int, input().split())    # n: 物の個数 w: 重さの限界

weight = [-1]*110
value = [-1]*110

dp = [[-1]*110]*110
for i in range(N):
    value[i], weight[i] = map(int, input().split())

# DPループ
for i in range(N):
    for w in range(W+1):
        if(w >= weight[i]):
            dp[i+1][w] = max(dp[i][w-weight[i]] + value[i], dp[i][w])
        else:
            dp[i+1][w] = dp[i][w]

print(dp[N][W])



Compiler output:
a.cc:1:37: error: stray '#' in program
    1 | N, W = map(int, input().split())    # n: 物の個数 w: 重さの限界
      |                                     ^
a.cc:10:3: error: invalid preprocessing directive #DP\U000030eb\U000030fc\U000030d7
   10 | # DPループ
      |   ^~~~~~~~
a.cc:1:1: error: 'N' does not name a type
    1 | N, W = map(int, input().split())    # n: 物の個数 w: 重さの限界
      | ^
Language: C++

#include<stdio.h>
#include<algorithm>


int memo[101][10001];

int v[101],w[101];

int dp(int i,int j){
    if(i == 0) return 0;

    if(memo[i][j] >= 0) return memo[i][j];

    if(j - w[i - 1] < 0) return dp(i - 1,j);

    return memo[i][j] = max(dp(i - 1,j),dp(i - 1,j - w[i - 1]) + v[i - 1]);
}

int main(){
    int N,W;
    scanf("%d%d",&N,&W);

    for(int i = 0;i < N;i++){
        scanf("%d%d",&v[i],&w[i]);
    }
    for(int i = 0;i <= N;i++){
        for(int j = 0;j <= W;j++){
            memo[i][j] = -1;
        }
    }

    printf("%d\n",dp(N,W));

}




Compiler output:
a.cc: In function 'int dp(int, int)':
a.cc:16:25: error: 'max' was not declared in this scope; did you mean 'std::max'?
   16 |     return memo[i][j] = max(dp(i - 1,j),dp(i - 1,j - w[i - 1]) + v[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)
      |     ^~~
Language: C++

#include <bits/stdc++.h>
using namespace std;
int DP[110][10010];
int main() {
  int N,W;
  cin >> N >> W;
  vector<int> v(N+1);
  vector<int> w(N+1);
  for(int i = 1;i <= N;i++)cin >> v[i] >> w[i];
  for(int i = 1;j <= N;i++){
    for(int j = 1;i <= W;j++){
      if(j >= w[i]){
        DP[i][j] = max({DP[i][j],DP[i-1][j-w[i]]+v[i],DP[i-1][j]});
      }
    }
  }
  cout << DP[N][W] << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:10:17: error: 'j' was not declared in this scope
   10 |   for(int i = 1;j <= N;i++){
      |                 ^
Language: C++

#include <cstdio>
#include <algorithm>
using namespace std;

int memo[101][1001];
int w[1001], v[1001];

int dp(int i, int j)
{
    if (i == 0)
        return 0;
    if (j - w[i - 1] < 0)
        return memo[i - 1][j];

    return memo[i][j] = max(memo[i - 1][j], (memo[i - 1][j - w[i - 1]]) - v[i - 1]);
}

int main()
{
    int N, W;
    for (int i = 0; i < 101; i++)
    {
        for (int j = 0; j < 10001)
        {
            memo[i][j] = -1;
        }
    }
    scanf("%d %d", &N, &W);
    for (int k = 0; k < N; k++)
    {
        scanf("%d %d", &v[k], &w[k]);
    }
    printf("%d", dp(N, W));
}



Compiler output:
a.cc: In function 'int main()':
a.cc:23:34: error: expected ';' before ')' token
   23 |         for (int j = 0; j < 10001)
      |                                  ^
      |                                  ;
Language: C++

#include <cstdio>
#include <algorithm>
using namespace std;

int memo[101][1001];
int w[1001], v[1001];

int dp(int i, int j)
{
    if (i == 0)
        return 0;
    if (j - w[i - 1] < 0)
        return memo[i - 1][j];

    return memo[i][j] = max(memo[i - 1][j], (memo[i - 1][j - w[i - 1]]) - v[i - 1]);
}

int main()
{
    int N, W;
    for (int i = 0; i < 101; i++)
    {
        for (int j = 0; j < 10001)
        {
            memo[i][j] = -1;
        }
    }
    scanf("%d %d", &N, &W);
    for (int k = 0; k < N; k++)
    {
        scanf("%d %d", &v[k], &w[k]);
    }
    printf("%d\n", dp(N, W));
}



Compiler output:
a.cc: In function 'int main()':
a.cc:23:34: error: expected ';' before ')' token
   23 |         for (int j = 0; j < 10001)
      |                                  ^
      |                                  ;
Language: C++

#include <vector>
#include <algorithm>
#include <cstdio>
using namespace std;
int N,B;
vector<pair<pair<int,int>,short> >item;//<value,weight>,i
vector<int>bag;

int main(){
	int i,j,r,m;
	scanf("%d%d",&N,&B);
	item.resize(N);
	bag.resize(B+1);
	back.resize(B+1);bag[0]=1;
	for(i=0;i<N;i++)scanf("%d%d",&item[i].first.first,&item[i].first.second),item[i].second=i;
	for(i=0;i<N;i++){
		for(j=B;j>=item[i].first.second;j--){
			if(bag[j-item[i].first.second]&&bag[j]<bag[j-item[i].first.second]+item[i].first.first){
				bag[j]=bag[j-item[i].first.second]+item[i].first.first;
			}
		}
	}
	for(r=i=0;i<=B;i++){
		if(r<bag[i]){
			r=bag[i];
			m=i;
		}
	}
	printf("%d\n",r-1);
}

Compiler output:
a.cc: In function 'int main()':
a.cc:14:9: error: 'back' was not declared in this scope
   14 |         back.resize(B+1);bag[0]=1;
      |         ^~~~
Language: C++

#include<iostream>
#include<algorithm>

#define nMAX 100
#define vMAX 1000
#define wMAX 1000
#define WMAX 10000

int n,W;
int v[nMAX],w[nMAX];
int dp[nMAX][WMAX];

using namespace std;

int rec(int i,int j){
	if(dp[i][j]>=0) return dp[i][j];
	int res;
	if(i==n) res=0;
	else if(j<w[i]) res=rec(i+1,j);
	else res=max(rec(i+1,j),rec(i+1,j-w[i])+v[i]);
	return dp[i][j]=res;
}

int main(void){
  std::ios_base::sync_with_stdio();

  cin>>n>>W;
  for(int i=0;i<n;i++){
	  cin>>v[i];
	  cin>>w[i];
  }
  memset(dp,-1,sizeof(dp));
  cout<<rec(0,W)<<endl;
 
  return 0;
}

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

import java.util.Scanner;
public class Main{
    public static int Max(int a, int b, int c){
        if(a >= b && a >= c)
            return a;
        else if(b >= c)
            return b;
        else
            return c;
    }
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int W = sc.nextInt();
        int v[] = new int[N];
        int w[] = new int[N];
        int dp[][] = new int[N+1][W+1];
        for(int i = 0 ; i <= W ; i++)
            dp[0][i] = 0;
        for(int i = 0 ; i < N ; i++){
            v[i] = sc.nextInt();
            w[i] = sc.nextInt();
        }
        for(int i = 0 ; i < N ; i++){
            for(int j = 0 ; j <= W ; j++){
                if(w[i] <= j)
                    dp[i+1][j] = Math.max(dp[i][j-w[i]]+v[i] , dp[i][j])
                else
                    dp[i+1][j] = dp[i][j];
            }
        }
        System.out.println(dp[N][W]);
    }
}


Compiler output:
Main.java:27: error: ';' expected
                    dp[i+1][j] = Math.max(dp[i][j-w[i]]+v[i] , dp[i][j])
                                                                        ^
1 error
Language: Java

import java.util.Scanner;

public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = Integer.parseInt(sc.next());
    int WW = Integer.parseInt(sc.next());
    int[] v = new int[N+1];
    int[] w = new int[N+1];
    for(int i=1; i<N+1; i++){
      v[i] = Integer.parseInt(sc.next());
      w[i] = Integer.parseInt(sc.next());
    }

    int[] dp = new int[WW+1];
    dp[0] = 0;

    for (int i=1; i<=N; i++) {
      for (int W=1; W<=WW; W++) {
            dp[i][W] = Math.max(dp[W], dp[W-w[i]] + v[i]);
      }
    }
      
    System.out.println(dp[WW]);
  }
}

Compiler output:
Main.java:20: error: array required, but int found
            dp[i][W] = Math.max(dp[W], dp[W-w[i]] + v[i]);
                 ^
1 error
Language: Java

package dp;

import java.util.ArrayList;
import java.util.Scanner;

public class KnapSackProblem {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(), s = sc.nextInt();
		ArrayList <KnapSackItem> items = new ArrayList<KnapSackItem>();
		for (int i =0 ;i < n; i++) {
			items.add(new KnapSackItem(sc.nextInt(), sc.nextInt()));
		}
		
		int[][] dp = new int[s+1][n+1];
		for (int i = 0; i < n ; i++) {
			dp[0][i] = 0;
		}
		for (int i = 0; i <= s ; i++) {
			dp[i][0] = 0;
		}
		for (int i = 1; i <= n ; i++) {
			for (int j = 1; j <= s ; j++) {
				for (int k = 0; k <= j; k++) {
					dp[j][i] = Math.max(dp[j][i], dp[k][i-1] + (j-k)/items.get(i-1).size * items.get(i-1).value);
				}
			}
		}
		System.out.println(dp[s][n]);
	}
	private static class KnapSackItem{
		int size, value;
		public KnapSackItem (int v, int s) {
			size = s; 
			value = v;
		}
	}
}

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