title: Highway Billboard Problem
signature: highway_billboard_problem <- function(m, x, revenue, n, t) {
test_code: 
  
  
  # SOLUTION CODE
  # ============================================
  PLACEHOLDER_CODE_BODY
  
  # TESTING CODE 
  # ============================================
  validate_solution <- function(actual, expected) {
      toString(actual)==toString(expected)
  }
  
  driver <- function(m, x, revenue, n, t, expected){
      if (validate_solution(PLACEHOLDER_FN_NAME(m, x, revenue, n, t), expected)){
          "PASSED"
      } else{
          "FAILED"
      }
  }
  
  main <- function() {
      cat(sprintf("TEST-0...%s\n",driver(
          16L, list(6L, 15L, 15L, 18L, 23L, 29L, 32L, 36L, 37L, 39L, 40L, 41L, 44L, 49L, 51L, 52L, 53L, 57L, 66L, 68L, 82L, 89L, 96L), list(1L, 2L, 5L, 5L, 24L, 26L, 31L, 32L, 33L, 41L, 57L, 59L, 71L, 75L, 79L, 87L, 87L, 88L, 92L, 94L, 96L, 96L, 99L), 12L, 12L, 
          2L
      )))
  
      cat(sprintf("TEST-1...%s\n",driver(
          39L, list(76L, 60L, 88L, 46L, -20L, -78L, -22L, 54L, -18L, 92L, -42L, -66L, -90L, -72L, -48L, 22L, -72L, -42L, -46L, 94L, 82L, -78L, 14L, 86L, 10L, -64L, -78L, 66L, 78L, -36L, 50L, -20L, -40L, -12L, 10L, -46L, 56L, -18L, 4L, -76L, -64L, 74L, 22L, 34L, 4L, -2L), list(28L, 8L, -60L, 84L, 68L, -54L, -56L, 0L, -68L, -84L, -6L, 92L, -80L, -24L, 86L, -6L, -44L, 82L, 74L, 90L, -46L, 40L, 62L, 50L, -42L, 38L, 78L, 94L, 46L, -14L, -48L, 66L, 70L, 52L, 10L, -88L, 54L, -10L, 98L, 34L, 16L, -2L, -62L, -56L, -40L, 86L), 25L, 27L, 
          0L
      )))
  
      cat(sprintf("TEST-2...%s\n",driver(
          5L, list(0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), list(0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L), 9L, 6L, 
          0L
      )))
  
      cat(sprintf("TEST-3...%s\n",driver(
          10L, list(21L, 69L, 30L, 10L, 71L, 72L, 71L, 78L, 30L, 9L, 72L, 10L, 7L, 87L, 30L, 46L, 56L, 74L, 73L, 60L, 86L), list(72L, 45L, 7L, 30L, 76L, 35L, 75L, 72L, 4L, 7L, 55L, 56L, 7L, 52L, 48L, 27L, 11L, 76L, 66L, 48L, 33L), 18L, 20L, 
          0L
      )))
  
      cat(sprintf("TEST-4...%s\n",driver(
          14L, list(-76L, -76L, -66L, -64L, -62L, -60L, -52L, -48L, -42L, -28L, -14L, -6L, -6L, 16L, 20L, 20L, 38L, 46L, 58L, 60L, 70L, 72L, 86L, 98L), list(-90L, -82L, -78L, -76L, -74L, -52L, -48L, -44L, -44L, -40L, -38L, -14L, -6L, 10L, 20L, 38L, 38L, 40L, 44L, 48L, 52L, 54L, 76L, 78L), 15L, 17L, 
          0L
      )))
  
      cat(sprintf("TEST-5...%s\n",driver(
          32L, list(1L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 0L, 0L, 0L, 1L, 0L, 0L, 1L, 1L, 0L, 0L, 1L, 1L, 1L, 0L, 1L, 0L, 1L, 1L, 0L, 1L, 0L, 1L), list(0L, 1L, 0L, 1L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 1L, 0L, 1L, 1L, 0L, 1L, 1L, 0L, 1L, 1L, 0L, 1L, 0L, 0L, 1L, 0L, 1L, 0L, 1L, 0L, 1L, 1L, 0L, 1L, 0L, 1L), 28L, 36L, 
          0L
      )))
  
      cat(sprintf("TEST-6...%s\n",driver(
          2L, list(16L, 38L, 72L, 82L), list(15L, 34L, 56L, 74L), 2L, 3L, 
          0L
      )))
  
      cat(sprintf("TEST-7...%s\n",driver(
          22L, list(28L, -76L, 42L, -2L, 30L, -10L, 52L, 66L, 26L, 96L, 96L, -72L, 26L, -86L, -30L, -78L, 32L, -32L, 58L, 12L, -72L, 8L, 34L, -68L, -28L, -66L), list(68L, -38L, 34L, 20L, 40L, 78L, 52L, 80L, 58L, -12L, -18L, 10L, 40L, 34L, 20L, -32L, -8L, -46L, 8L, 62L, 94L, -30L, -94L, 26L, -40L, 64L), 13L, 16L, 
          0L
      )))
  
      cat(sprintf("TEST-8...%s\n",driver(
          15L, list(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), list(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), 25L, 15L, 
          0L
      )))
  
      cat(sprintf("TEST-9...%s\n",driver(
          8L, list(95L, 12L, 65L, 97L, 92L, 49L, 94L, 32L, 37L, 97L, 9L, 35L), list(25L, 32L, 14L, 49L, 90L, 37L, 92L, 1L, 8L, 75L, 50L, 9L), 9L, 8L, 
          0L
      )))
  
  }
  
  main()
source_py: def highway_billboard_problem(m, x, revenue, n, t):
      maxRev = ([0] * (m + 1))
      nxtbb = 0
      for i in range(1, (m + 1)):
          if (nxtbb < n):
              if (x[nxtbb] != i):
                  maxRev[i] = maxRev[(i - 1)]
              else:
                  if (i <= t):
                      maxRev[i] = max(maxRev[(i - 1)], revenue[nxtbb])
                  else:
                      maxRev[i] = max((maxRev[((i - t) - 1)] + revenue[nxtbb]), maxRev[(i - 1)])
                  nxtbb += 1
          else:
              maxRev[i] = maxRev[(i - 1)]
      return maxRev[m]
source_cpp: int highway_billboard_problem(int m, vector<int> x, vector<int> revenue, int n, int t) {
    int maxRev [ m + 1 ];
    memset ( maxRev, 0, sizeof ( maxRev ) );
    int nxtbb = 0;
    for ( int i = 1;
    i <= m;
    i ++ ) {
      if ( nxtbb < n ) {
        if ( x [ nxtbb ] != i ) maxRev [ i ] = maxRev [ i - 1 ];
        else {
          if ( i <= t ) maxRev [ i ] = max ( maxRev [ i - 1 ], revenue [ nxtbb ] );
          else maxRev [ i ] = max ( maxRev [ i - t - 1 ] + revenue [ nxtbb ], maxRev [ i - 1 ] );
          nxtbb ++;
        }
      }
      else maxRev [ i ] = maxRev [ i - 1 ];
    }
    return maxRev [ m ];
  }