Solution to the MinAvgTwoSlice problem in C++