• + 0 comments

    Hi, I have got a WA at case #4. But I check every output of my code with the answer, they are the same. Can someone know what happened?

    Here is my code

    object Solution {
    
     def dpSolver(A:Array[Int], query:Array[Array[Int]] ):Unit = {
        val dp = Array.fill(A.length, A.length)(Int.MaxValue)
        for{i <- A.indices} dp(i)(i) = A(i)
        for{
          i <- A.indices
          j <- i + 1 until A.length
        }
          dp(i)(j) =  A(j) min dp(i)(j-1)
        query foreach {case Array(i,j) => println(dp(i)(j))}
      }
    
      def readArray():Array[Int] = readLine.split(' ').map(_.toInt)
      def main(args: Array[String]) {
        readArray match {
          case Array(n, m) => dpSolver( readArray, Array.fill(m)(readArray))
        }
      }
    }