Goodland Electricity

  • + 0 comments

    My approach for this was essentially: given a city position, find the optimal point to place a power plant for that city position. Once I find a place for it, move to the furthest out city position not covered by the power plant I just placed, and do that again. Continue doing that until I reach the end of the array.

    To find the optimal position for a given city, I use the k value to go as far out as possible (taking care to remain in-bounds of the array). I check if the position can contain a power plant. If it can, I use that position. If not, I reduce the value by one and continue. The lowest value is the previously placed power plant + 1 (or 0 if none has been placed yet).