The advantage of cooperation for moderate switching between group exclusion and group reward in the spatial public goods game