Optimal Adaptive Group Sequential Procedure for Finite Populations in the Presence of a Cost Function