Language: Java

import java.io.*;
 
class Main{
public static void main(String[] args) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String line="";
int count=1;
while(!(line=br.readLine()).equals("0")){
int weight=0;
static int W=Integer.parseInt(line);
static int n=Integer.parseInt(br.readLine());
static int[] v=new int[n];
static int[] w=new int[n];
static int[][] dp=new int[n+1][W+1];
static boolean[] use=new boolean[n];
for(int i=0;i<n;i++){
String[] str=br.readLine().split(",");
v[i]=Integer.parseInt(str[0]);
w[i]=Integer.parseInt(str[1]);
}
System.out.println("Case "+count+":");
System.out.println(MaxValue(0,W));
for(int i=0;i<n;i++){
if(use[i]){
weight+=w[i];
}
System.out.println(weight);
count++;
}
}
private static int MaxValue(int W,int n,int[] v,int[] w,int[][] dp,int i,int j){
if(dp[i][j]!=0){
return dp[i][j];
}
else if(i==n){
return 0;
}
else if(j>w[i]){
use[i]=false;
return dp[i][j]=MaxValue(int W,int n,int[] v,int[] w,int[][] dp,i+1,j);
}
else{
int p=MaxValue(int W,int n,int[] v,int[] w,int[][] dp,i+1,j);
int q=MaxValue(int W,int n,int[] v,int[] w,int[][] dp,i+1,j-w[i])+v[i];
int r=Math.max(p,q);
use[i]=(p==r)?false:true;
return dp[i][j]=r;
}
}
}

Compiler output:
Main.java:10: error: illegal start of expression
static int W=Integer.parseInt(line);
^
Main.java:16: error: illegal start of type
for(int i=0;i<n;i++){
^
Main.java:16: error: > or ',' expected
for(int i=0;i<n;i++){
               ^
Main.java:16: error: <identifier> expected
for(int i=0;i<n;i++){
                 ^
Main.java:21: error: <identifier> expected
System.out.println("Case "+count+":");
                  ^
Main.java:21: error: illegal start of type
System.out.println("Case "+count+":");
                   ^
Main.java:22: error: <identifier> expected
System.out.println(MaxValue(0,W));
                  ^
Main.java:22: error: <identifier> expected
System.out.println(MaxValue(0,W));
                           ^
Main.java:23: error: illegal start of type
for(int i=0;i<n;i++){
^
Main.java:23: error: > or ',' expected
for(int i=0;i<n;i++){
               ^
Main.java:23: error: <identifier> expected
for(int i=0;i<n;i++){
                 ^
Main.java:40: error: not a statement
return dp[i][j]=MaxValue(int W,int n,int[] v,int[] w,int[][] dp,i+1,j);
                             ^
Main.java:40: error: not a statement
return dp[i][j]=MaxValue(int W,int n,int[] v,int[] w,int[][] dp,i+1,j);
                                                                    ^
Main.java:43: error: not a statement
int p=MaxValue(int W,int n,int[] v,int[] w,int[][] dp,i+1,j);
                   ^
Main.java:43: error: not a statement
int p=MaxValue(int W,int n,int[] v,int[] w,int[][] dp,i+1,j);
                                                          ^
Main.java:44: error: not a statement
int q=MaxValue(int W,int n,int[] v,int[] w,int[][] dp,i+1,j-w[i])+v[i];
                   ^
Main.java:44: error: not a statement
int q=MaxValue(int W,int n,int[] v,int[] w,int[][] dp,i+1,j-w[i])+v[i];
                                                           ^
Main.java:44: error: not a statement
int q=MaxValue(int W,int n,int[] v,int[] w,int[][] dp,i+1,j-w[i])+v[i];
                                                                   ^
Main.java:31: error: unnamed classes are a preview feature and are disabled by default.
private static int MaxValue(int W,int n,int[] v,int[] w,int[][] dp,int i,int j){
               ^
  (use --enable-preview to enable unnamed classes)
Main.java:40: error: ';' expected
return dp[i][j]=MaxValue(int W,int n,int[] v,int[] w,int[][] dp,i+1,j);
                              ^
Main.java:40: error: <identifier> expected
return dp[i][j]=MaxValue(int W,int n,int[] v,int[] w,int[][] dp,i+1,j);
                                     ^
Main.java:40: error: <identifier> expected
return dp[i][j]=MaxValue(int W,int n,int[] v,int[] w,int[][] dp,i+1,j);
                                             ^
Main.java:40: error: <identifier> expected
return dp[i][j]=MaxValue(int W,int n,int[] v,int[] w,int[][] dp,i+1,j);
                                                     ^
Main.java:40: error: ';' expected
return dp[i][j]=MaxValue(int W,int n,int[] v,int[] w,int[][] dp,i+1,j);
                                                                 ^
Main.java:40: error: ';' expected
return dp[i][j]=MaxValue(int W,int n,int[] v,int[] w,int[][] dp,i+1,j);
                                                                     ^
Main.java:43: error: ';' expected
int p=MaxValue(int W,int n,int[] v,int[] w,int[][] dp,i+1,j);
                    ^
Main.java:43: error: <identifier> expected
int p=MaxValue(int W,int n,int[] v,int[] w,int[][] dp,i+1,j);
                           ^
Main.java:43: error: <identifier> expected
int p=MaxValue(int W,int n,int[] v,int[] w,int[][] dp,i+1,j);
                                   ^
Main.java:43: error: <identifier> expected
int p=MaxValue(int W,int n,int[] v,int[] w,int[][] dp,i+1,j);
                                           ^
Main.java:43: error: ';' expected
int p=MaxValue(int W,int n,int[] v,int[] w,int[][] dp,i+1,j);
                                                       ^
Main.java:43: error: ';' expected
int p=MaxValue(int W,int n,int[] v,int[] w,int[][] dp,i+1,j);
                                                           ^
Main.java:44: error: ';' expected
int q=MaxValue(int W,int n,int[] v,int[] w,int[][] dp,i+1,j-w[i])+v[i];
                    ^
Main.java:44: error: <identifier> expected
int q=MaxValue(int W,int n,int[] v,int[] w,int[][] dp,i+1,j-w[i])+v[i];
                           ^
Main.java:44: error: <identifier> expected
int q=MaxValue(int W,int n,int[] v,int[] w,int[][] dp,i+1,j-w[i])+v[i];
                                   ^
Main.java:44: error: <identifier> expected
int q=MaxValue(int W,int n,int[] v,int[] w,int[][] dp,i+1,j-w[i])+v[i];
                                           ^
Main.java:44: error: ';' expected
int q=MaxValue(int W,int n,int[] v,int[] w,int[][] dp,i+1,j-w[i])+v[i];
                                                       ^
Main.java:44: error: ';' expected
int q=MaxValue(int W,int n,int[] v,int[] w,int[][] dp,i+1,j-w[i])+v[i];
                                                                ^
Main.java:50: error: class, interface, enum, or record expected
}
^
38 errors