• + 0 comments

    solution via relatively straightforward dynamic programming. weirdly this doesn't fit with the way the problem wants you to compute the values for each query separately - for this you'd have to maintain the value table w/o knowing its final size, which is very awkward - a lot easier to change the input parsing code so that it sends all queries at once so that they can be processed together.