Language: C++

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

public class Main {
  public static void main(String[] args) throws IOException {
    Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
    int n = in.nextInt();
    int W = in.nextInt();
    int[] w = new int[n];
    int[] v = new int[n];
    for (int i = 0; i < n; i++) {
      w[i] = in.nextInt();
      v[i] = in.nextInt();
    }
    final Solver solve = new Solver();
    System.out.println(solve.solve(W, w, v));
  }
}


class Solver {
  public long solve(int W, int[] w, int[] v) {
    int n = w.length;
    int sum = 0;
    for (int i = 0; i < n; i++) {
      sum += v[i];
    }
    long[] dp = new long[sum+1];
    Arrays.fill(dp, n * 1000 + 1);
    dp[0] = 0;
    for (int i = 0; i < n; i++) {
      for (int j = sum; j >= v[i]; j--) {
        dp[j] = Math.min(dp[j], dp[j-v[i]]+w[i]);
      }
    }
    long answer = 0;
    for (int i = 0; i < dp.length; i++) {
      if (dp[i] <= W) {
        answer = Math.max(answer, i);
      }
    }
    return answer;
  }
}


Compiler output:
a.cc:1:1: error: 'import' does not name a type
    1 | import java.io.BufferedReader;
      | ^~~~~~
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.io.IOException;
      | ^~~~~~
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.io.InputStreamReader;
      | ^~~~~~
a.cc:3:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:4:1: error: 'import' does not name a type
    4 | import java.util.Arrays;
      | ^~~~~~
a.cc:4:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:5:1: error: 'import' does not name a type
    5 | import java.util.Scanner;
      | ^~~~~~
a.cc:5:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:7:1: error: expected unqualified-id before 'public'
    7 | public class Main {
      | ^~~~~~
a.cc:25:9: error: expected ':' before 'long'
   25 |   public long solve(int W, int[] w, int[] v) {
      |         ^~~~~
      |         :
a.cc:25:34: error: expected ',' or '...' before 'w'
   25 |   public long solve(int W, int[] w, int[] v) {
      |                                  ^
a.cc:47:2: error: expected ';' after class definition
   47 | }
      |  ^
      |  ;
a.cc: In member function 'long int Solver::solve(int, int*)':
a.cc:26:13: error: 'w' was not declared in this scope
   26 |     int n = w.length;
      |             ^
a.cc:29:14: error: 'v' was not declared in this scope
   29 |       sum += v[i];
      |              ^
a.cc:31:9: error: structured binding declaration cannot have type 'long int'
   31 |     long[] dp = new long[sum+1];
      |         ^~
a.cc:31:9: note: type must be cv-qualified 'auto' or reference to cv-qualified 'auto'
a.cc:31:9: error: empty structured binding declaration
a.cc:31:12: error: expected initializer before 'dp'
   31 |     long[] dp = new long[sum+1];
      |            ^~
a.cc:32:5: error: 'Arrays' was not declared in this scope
   32 |     Arrays.fill(dp, n * 1000 + 1);
      |     ^~~~~~
a.cc:32:17: error: 'dp' was not declared in this scope
   32 |     Arrays.fill(dp, n * 1000 + 1);
      |                 ^~
a.cc:35:30: error: 'v' was not declared in this scope
   35 |       for (int j = sum; j >= v[i]; j--) {
      |                              ^
a.cc:36:17: error: 'Math' was not declared in this scope
   36 |         dp[j] = Math.min(dp[j], dp[j-v[i]]+w[i]);
      |                 ^~~~
a.cc:42:18: error: 'Math' was not declared in this scope
   42 |         answer = Math.max(answer, i);
      |                  ^~~~