Language: Java

import java.util.Scanner;
class Solution
{
  public static long knapsack(long[] wt, long[] val, long n, long w, long[][] dp)
  {
    for(long i = 1; i <= n; i++)
    {
      for(long j = 1; j <= w; j++)
      {
        if(wt[i - 1] <= j)
        {
          dp[i][j] = Math.max((val[i - 1] + dp[i - 1][j - wt[i - 1]]), dp[i - 1][j]);
        }
        else
                                                      {
                                                        dp[i][j] = dp[i - 1][j];
                                                      }
                                                        
                                                      
      }
    }
                                                      return dp[n][w];
  }
  public static void main(String[] args)
  {
    Scanner scan = new Scanner(System.in);
    long n = scan.nextlong();
    long w = scan.nextlong();
    long wt[] = new long[n];
    long val[] = new long[n];
    for(long i = 0; i < n; i++)
    {
      wt[i] = scan.nextlong();
      val[i] = scan.nextlong();
    }
    long[][] dp = new long[n + 1][w + 1];
    long maxProfit = knapsack(wt, val, n, w, dp);
    System.out.prlongln(maxProfit);
  }
}


Compiler output:
Main.java:10: error: incompatible types: possible lossy conversion from long to int
        if(wt[i - 1] <= j)
                ^
Main.java:12: error: incompatible types: possible lossy conversion from long to int
          dp[i][j] = Math.max((val[i - 1] + dp[i - 1][j - wt[i - 1]]), dp[i - 1][j]);
             ^
Main.java:12: error: incompatible types: possible lossy conversion from long to int
          dp[i][j] = Math.max((val[i - 1] + dp[i - 1][j - wt[i - 1]]), dp[i - 1][j]);
                ^
Main.java:12: error: incompatible types: possible lossy conversion from long to int
          dp[i][j] = Math.max((val[i - 1] + dp[i - 1][j - wt[i - 1]]), dp[i - 1][j]);
                                                                            ^
Main.java:12: error: incompatible types: possible lossy conversion from long to int
          dp[i][j] = Math.max((val[i - 1] + dp[i - 1][j - wt[i - 1]]), dp[i - 1][j]);
                                                                                 ^
Main.java:12: error: incompatible types: possible lossy conversion from long to int
          dp[i][j] = Math.max((val[i - 1] + dp[i - 1][j - wt[i - 1]]), dp[i - 1][j]);
                                     ^
Main.java:12: error: incompatible types: possible lossy conversion from long to int
          dp[i][j] = Math.max((val[i - 1] + dp[i - 1][j - wt[i - 1]]), dp[i - 1][j]);
                                                 ^
Main.java:12: error: incompatible types: possible lossy conversion from long to int
          dp[i][j] = Math.max((val[i - 1] + dp[i - 1][j - wt[i - 1]]), dp[i - 1][j]);
                                                               ^
Main.java:12: error: incompatible types: possible lossy conversion from long to int
          dp[i][j] = Math.max((val[i - 1] + dp[i - 1][j - wt[i - 1]]), dp[i - 1][j]);
                                                        ^
Main.java:16: error: incompatible types: possible lossy conversion from long to int
                                                        dp[i][j] = dp[i - 1][j];
                                                           ^
Main.java:16: error: incompatible types: possible lossy conversion from long to int
                                                        dp[i][j] = dp[i - 1][j];
                                                              ^
Main.java:16: error: incompatible types: possible lossy conversion from long to int
                                                        dp[i][j] = dp[i - 1][j];
                                                                        ^
Main.java:16: error: incompatible types: possible lossy conversion from long to int
                                                        dp[i][j] = dp[i - 1][j];
                                                                             ^
Main.java:22: error: incompatible types: possible lossy conversion from long to int
                                                      return dp[n][w];
                                                                ^
Main.java:22: error: incompatible types: possible lossy conversion from long to int
                                                      return dp[n][w];
                                                                   ^
Main.java:27: error: cannot find symbol
    long n = scan.nextlong();
                 ^
  symbol:   method nextlong()
  location: variable scan of type Scanner
Main.java:28: error: cannot find symbol
    long w = scan.nextlong();
                 ^
  symbol:   method nextlong()
  location: variable scan of type Scanner
Main.java:29: error: incompatible types: possible lossy conversion from long to int
    long wt[] = new long[n];
                         ^
Main.java:30: error: incompatible types: possible lossy conversion from long to int
    long val[] = new long[n];
                          ^
Main.java:33: error: incompatible types: possible lossy conversion from long to int
      wt[i] = scan.nextlong();
         ^
Main.java:33: error: cannot find symbol
      wt[i] = scan.nextlong();
                  ^
  symbol:   method nextlong()
  location: variable scan of type Scanner
Main.java:34: error: incompatible types: possible lossy conversion from long to int
      val[i] = scan.nextlong();
          ^
Main.java:34: error: cannot find symbol
      val[i] = scan.nextlong();
                   ^
  symbol:   method nextlong()
  location: variable scan of type Scanner
Main.java:36: error: incompatible types: possible lossy conversion from long to int
    long[][] dp = new long[n + 1][w + 1];
                             ^
Main.java:36: error: incompatible types: possible lossy conversion from long to int
    long[][] dp = new long[n + 1][w + 1];
                                    ^
Main.java:38: error: cannot find symbol
    System.out.prlongln(maxProfit);
              ^
  symbol:   method prlongln(long)
  location: variable out of type PrintStream
26 errors