Improving the running time a little bit

If you just reset the the temp_sum when the start row moves, 
you could improve this down to O(n^3)

Note: These were my first 3 characters of Ruby ever, so I'm sorry
if I messed something up :P Just trying to expose the idea.