This article presents a solution to the leaderless formation control problem for first-order multiagent systems, which minimizes a global function composed of a sum of local strongly convex functions for each agent under weighted undirected graphs within a predefined time. The proposed distributed optimization process consists of two steps: 1) the controller initially leads each agent to the minimizer of its local function and 2) then guides all agents toward achieving leaderless formation and reaching the global function's minimizer. The proposed scheme requires fewer adjustable parameters than most existing methods in the literature without the need for auxiliary variables or time-variable gains. Additionally, one can consider highly nonlinear multivalued strongly convex cost functions, while the agents do not share the gradients and Hessians. Extensive simulations and comparisons with state-of-the-art algorithms demonstrate the effectiveness of our approach.