In the implementation dp [ n ] [ k ] represents maximum sum subsequence of length k and the subsequence is ending at index n .
let dp = new Array ( n ) ; for ( let i = 0 ; i < dp . length ; i ++ ) { dp [ i ] = new Array ( 2 ) ; } let ans = - 1 ;