If in the extremal case (which exists, since we are dealing with a finite number of possible cases) we replace the $m$ pairwise distinct positive even integers with the first $m$ such, and the $n$ pairwise distinct positive odd integers with the first $n$ such, we get the constraint $m(m+1) + n^2 \leq 1987$, under which we have to maximize $3m+4n$. But $x(x+1) + y^2 = (x+1/2)^2 + y^2 = 1987+1/4$ is a circle $\gamma$, while $3x+4y=k$ are a pencil of parallel lines $\ell_k$, so the maximum value for $k$ is reached when $\ell_k$ is tangent at $\gamma$; then it only remains to find the closest integers to the (real) coordinates of the tangency point.