title: Maximum Sum Subsequence Least K Distant Elements
signature: fun maximumSumSubsequenceLeastKDistantElements(arr: ArrayList<Int>, n: Int, k: Int): Int {
source_py: def maximum_sum_subsequence_least_k_distant_elements(arr, N, k):
      MS = [0 for i in range(N)]
      MS[(N - 1)] = arr[(N - 1)]
      for i in range((N - 2), (- 1), (- 1)):
          if (((i + k) + 1) >= N):
              MS[i] = max(arr[i], MS[(i + 1)])
          else:
              MS[i] = max((arr[i] + MS[((i + k) + 1)]), MS[(i + 1)])
      return MS[0]
source_cpp: int maximum_sum_subsequence_least_k_distant_elements(vector<int> arr, int N, int k) {
    int MS [ N ];
    MS [ N - 1 ] = arr [ N - 1 ];
    for ( int i = N - 2;
    i >= 0;
    i -- ) {
      if ( i + k + 1 >= N ) MS [ i ] = max ( arr [ i ], MS [ i + 1 ] );
      else MS [ i ] = max ( arr [ i ] + MS [ i + k + 1 ], MS [ i + 1 ] );
    }
    return MS [ 0 ];
  }
question_info.test_list: [{"idx": 0, "outputs": 98, "inputs": {"arr": [3, 5, 20, 21, 23, 26, 27, 31, 33, 38, 39, 41, 48, 48, 50, 51, 56, 57, 64, 68, 69, 70, 71, 74, 76, 86, 97], "n": 23, "k": 15}}, {"idx": 1, "outputs": 90, "inputs": {"arr": [32, 34, -40, 90, -82, -70, 30, 26, -76, -46, -84, 76, -76], "n": 9, "k": 10}}, {"idx": 2, "outputs": 0, "inputs": {"arr": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], "n": 22, "k": 34}}, {"idx": 3, "outputs": 96, "inputs": {"arr": [96, 15, 30, 25, 83], "n": 2, "k": 3}}, {"idx": 4, "outputs": 26, "inputs": {"arr": [-90, -82, -80, -76, -62, -58, -50, -48, -46, -38, -38, -38, -38, -38, -34, -32, -24, -22, -16, -16, -4, -2, 10, 10, 20, 26, 26, 32, 38, 38, 44, 44, 46, 48, 58, 62, 64, 66, 76, 78, 78, 82, 92, 96, 96, 98], "n": 27, "k": 30}}, {"idx": 5, "outputs": 1, "inputs": {"arr": [1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 1, 0, 0], "n": 9, "k": 9}}, {"idx": 6, "outputs": 72, "inputs": {"arr": [1, 2, 9, 17, 24, 31, 31, 33, 56, 57, 61, 71, 73, 74, 76, 77, 79, 83, 86, 95, 99], "n": 12, "k": 10}}, {"idx": 7, "outputs": 80, "inputs": {"arr": [-12, 52, -44, 80, -66, 34, 42, -46, 8, 12, -22, -56, 74, -98, -44, 2, -24, -14, -54, -56, -26, -18, -72], "n": 13, "k": 19}}, {"idx": 8, "outputs": 1, "inputs": {"arr": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], "n": 13, "k": 13}}, {"idx": 9, "outputs": 155, "inputs": {"arr": [65, 1, 34, 38, 15, 6, 55, 21, 32, 90, 39, 25, 43, 48, 64, 66, 88, 70, 82, 75, 25, 56, 23, 27, 41, 33, 33, 55, 60, 90, 41, 58, 42, 53, 38, 90, 7, 15], "n": 37, "k": 33}}]
question_info.extension: kts
question_info.test_code: package main
  
  import kotlin.text.*
  import kotlin.math.*
  
  
  // SOLUTION CODE
  // ===================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE
  // ===================================
  fun validateSolution(actual:Int, expected:Int):Boolean{
    return actual.equals(expected)
  }
  fun driver(arr: ArrayList<Int>, n: Int, k: Int, expected:Int):String {
      try{
        if (validateSolution(PLACEHOLDER_FN_NAME(arr, n, k), expected)) {
                return "PASSED"
        }
        return "FAILED"
      } catch (e: Exception){
        return e::class.simpleName as String
      }
  
  }
  
  fun main() {
      var result: String = ""
      result = driver(arrayListOf(3, 5, 20, 21, 23, 26, 27, 31, 33, 38, 39, 41, 48, 48, 50, 51, 56, 57, 64, 68, 69, 70, 71, 74, 76, 86, 97), 23, 15, 98)
      println("TEST-0...${result}")
      
      result = driver(arrayListOf(32, 34, -40, 90, -82, -70, 30, 26, -76, -46, -84, 76, -76), 9, 10, 90)
      println("TEST-1...${result}")
      
      result = driver(arrayListOf(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1), 22, 34, 0)
      println("TEST-2...${result}")
      
      result = driver(arrayListOf(96, 15, 30, 25, 83), 2, 3, 96)
      println("TEST-3...${result}")
      
      result = driver(arrayListOf(-90, -82, -80, -76, -62, -58, -50, -48, -46, -38, -38, -38, -38, -38, -34, -32, -24, -22, -16, -16, -4, -2, 10, 10, 20, 26, 26, 32, 38, 38, 44, 44, 46, 48, 58, 62, 64, 66, 76, 78, 78, 82, 92, 96, 96, 98), 27, 30, 26)
      println("TEST-4...${result}")
      
      result = driver(arrayListOf(1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 1, 0, 0), 9, 9, 1)
      println("TEST-5...${result}")
      
      result = driver(arrayListOf(1, 2, 9, 17, 24, 31, 31, 33, 56, 57, 61, 71, 73, 74, 76, 77, 79, 83, 86, 95, 99), 12, 10, 72)
      println("TEST-6...${result}")
      
      result = driver(arrayListOf(-12, 52, -44, 80, -66, 34, 42, -46, 8, 12, -22, -56, 74, -98, -44, 2, -24, -14, -54, -56, -26, -18, -72), 13, 19, 80)
      println("TEST-7...${result}")
      
      result = driver(arrayListOf(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1), 13, 13, 1)
      println("TEST-8...${result}")
      
      result = driver(arrayListOf(65, 1, 34, 38, 15, 6, 55, 21, 32, 90, 39, 25, 43, 48, 64, 66, 88, 70, 82, 75, 25, 56, 23, 27, 41, 33, 33, 55, 60, 90, 41, 58, 42, 53, 38, 90, 7, 15), 37, 33, 155)
      println("TEST-9...${result}")
      
          
  }
  
  main()
question_info.entry_fn_name: maximumSumSubsequenceLeastKDistantElements
question_info.entry_cls_name: Solution
question_info.test_case_ids: 0 1 2 3 4 5 6 7 8 9
question_info.commands: kotlinc -script __FILENAME__ -no-reflect -nowarn