title: Minimum Time Write Characters Using Insert Delete Copy Operation
signature: fun minimumTimeWriteCharactersUsingInsertDeleteCopyOperation(n: Int, insrt: Int, remov: Int, cpy: Int): Int {
source_py: def minimum_time_write_characters_using_insert_delete_copy_operation(N, insrt, remov, cpy):
      if (N == 0):
          return 0
      if (N == 1):
          return insrt
      dp = ([0] * (N + 1))
      for i in range(1, (N + 1)):
          if ((i % 2) == 0):
              dp[i] = min((dp[(i - 1)] + insrt), (dp[(i // 2)] + cpy))
          else:
              dp[i] = min((dp[(i - 1)] + insrt), ((dp[((i + 1) // 2)] + cpy) + remov))
      return dp[N]
source_cpp: int minimum_time_write_characters_using_insert_delete_copy_operation(int N, int insert, int remove, int copy) {
    if ( N == 0 ) return 0;
    if ( N == 1 ) return insert;
    int dp [ N + 1 ];
    memset ( dp, 0, sizeof ( dp ) );
    for ( int i = 1;
    i <= N;
    i ++ ) {
      if ( i % 2 == 0 ) dp [ i ] = min ( dp [ i - 1 ] + insert, dp [ i / 2 ] + copy );
      else dp [ i ] = min ( dp [ i - 1 ] + insert, dp [ ( i + 1 ) / 2 ] + copy + remove );
    }
    return dp [ N ];
  }
question_info.test_list: [{"idx": 0, "outputs": 351, "inputs": {"n": 59, "insrt": 75, "remov": 12, "cpy": 45}}, {"idx": 1, "outputs": 382, "inputs": {"n": 66, "insrt": 68, "remov": 32, "cpy": 41}}, {"idx": 2, "outputs": 195, "inputs": {"n": 98, "insrt": 55, "remov": 69, "cpy": 5}}, {"idx": 3, "outputs": 76, "inputs": {"n": 63, "insrt": 4, "remov": 41, "cpy": 12}}, {"idx": 4, "outputs": 460, "inputs": {"n": 99, "insrt": 37, "remov": 98, "cpy": 55}}, {"idx": 5, "outputs": 147, "inputs": {"n": 45, "insrt": 28, "remov": 59, "cpy": 7}}, {"idx": 6, "outputs": 405, "inputs": {"n": 60, "insrt": 53, "remov": 40, "cpy": 52}}, {"idx": 7, "outputs": 392, "inputs": {"n": 11, "insrt": 96, "remov": 50, "cpy": 50}}, {"idx": 8, "outputs": 694, "inputs": {"n": 96, "insrt": 95, "remov": 48, "cpy": 84}}, {"idx": 9, "outputs": 244, "inputs": {"n": 54, "insrt": 6, "remov": 50, "cpy": 82}}]
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(n: Int, insrt: Int, remov: Int, cpy: Int, expected:Int):String {
      try{
        if (validateSolution(PLACEHOLDER_FN_NAME(n, insrt, remov, cpy), expected)) {
                return "PASSED"
        }
        return "FAILED"
      } catch (e: Exception){
        return e::class.simpleName as String
      }
  
  }
  
  fun main() {
      var result: String = ""
      result = driver(59, 75, 12, 45, 351)
      println("TEST-0...${result}")
      
      result = driver(66, 68, 32, 41, 382)
      println("TEST-1...${result}")
      
      result = driver(98, 55, 69, 5, 195)
      println("TEST-2...${result}")
      
      result = driver(63, 4, 41, 12, 76)
      println("TEST-3...${result}")
      
      result = driver(99, 37, 98, 55, 460)
      println("TEST-4...${result}")
      
      result = driver(45, 28, 59, 7, 147)
      println("TEST-5...${result}")
      
      result = driver(60, 53, 40, 52, 405)
      println("TEST-6...${result}")
      
      result = driver(11, 96, 50, 50, 392)
      println("TEST-7...${result}")
      
      result = driver(96, 95, 48, 84, 694)
      println("TEST-8...${result}")
      
      result = driver(54, 6, 50, 82, 244)
      println("TEST-9...${result}")
      
          
  }
  
  main()
question_info.entry_fn_name: minimumTimeWriteCharactersUsingInsertDeleteCopyOperation
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