If you did 1 minute at 300 watts, 1 minute at 100 watts and then another minute at 300 watts, the average for 2 minutes would be 200 watts but the average for 3 minutes would be 233 watts.
That’s the basis for how longer time-frames can have higher averages.
If the best 40 minute interval has a dip in power in the middle, then it may not be possible to find a 30 minute subset of that 40 minutes that has the same average power. If you think as the 40 minute interval as two peaks either side with a dip in the middle, a 30 minute window might only be able to incorporate one of the peaks thus giving a lower 30 minute average than 40 minute average.