Solution (source code)

= Solution

Use the intended trace bound $\operatorname{Ric}\geq(n-1)kg$ and write $D=\pi/\sqrt k$. We state precisely the allowed <Bishop volume comparison with a positive-curvature model>. Set
$$
s_k(r)=\frac{\sin(\sqrt k\,r)}{\sqrt k},\qquad v_k(r)=\omega_{n-1}\int_0^r s_k(t)^{n-1}\,dt,
$$
where $\omega_{n-1}$ is the area of the unit $(n-1)$-sphere. For $V_p(r)=\operatorname{Vol}B(p,r)$, the ratio $V_p(r)/v_k(r)$ is nonincreasing on $0<r<D$, tends to one at zero, and is at most one. Before the cut time, the radial volume density $J(r,\theta)$ in <geodesic polar coordinates> is at most $s_k(r)^{n-1}$.

By the <Bonnet-Myers theorem>, $\operatorname{diam}M\leq D$. Therefore $V_p(D)=\operatorname{Vol}M$. If distance-$D$ endpoints exist, they do not affect this volume equality: the distance sphere is contained in the smooth image $\exp_p(D S_p^{n-1})$, which has zero $n$-dimensional <Riemannian volume>. Taking limits in the comparison ratio at $D$ is legitimate. The assumed equality of total volume gives $V_p(D)/v_k(D)=1$, so monotonicity forces
$$
V_p(r)=v_k(r)\qquad(0<r<D)
$$
for every $p$.

We now extract the equality geometry, rather than merely naming a rigidity theorem. On a small <normal neighborhood> of $p$, the continuous nonnegative difference $s_k(r)^{n-1}-J(r,\theta)$ has integral zero. It is therefore identically zero. Let $A(X)=\nabla_X\partial_r$ on a distance sphere and $h=\operatorname{tr}A=\partial_r\log J$. Equality of the density gives $h=(n-1)s_k'/s_k$. The traced <radial Riccati equation for distance spheres> reads
$$
h'+\operatorname{tr}(A^2)+\operatorname{Ric}(\partial_r,\partial_r)=0.
$$
Since $s_k''=-ks_k$, substituting $h$ makes the sum of the following two nonnegative quantities zero:
$$
\left(\operatorname{tr}(A^2)-\frac{h^2}{n-1}\right)+\left(\operatorname{Ric}(\partial_r,\partial_r)-(n-1)k\right)=0.
$$
Equality in the <Cauchy-Schwarz inequality> for the <eigenvalues> of the self-adjoint operator $A$ forces $A=(s_k'/s_k)I$. The angular metric $g_r$ in <geodesic polar coordinates> consequently satisfies $\partial_rg_r=2(s_k'/s_k)g_r$. Smoothness at the center fixes its integration constant, since $r^{-2}g_r\to g_{S^{n-1}}$. Hence
$$
g=dr^2+s_k(r)^2g_{S^{n-1}}
$$
on the normal ball: the <Riemannian metric> is locally the round curvature-$k$ metric. As $p$ was arbitrary, $M$ has constant <sectional curvature> $k$.

The <classification of complete positive constant-curvature manifolds> now gives $M=S_k^n/\Gamma$ with $\Gamma$ a finite freely acting group of <isometries>. Covering degree gives $\operatorname{Vol}M=\operatorname{Vol}S_k^n/|\Gamma|$. Volume equality forces $|\Gamma|=1$, proving
$$
\boxed{M\cong S_k^n.}
$$
This establishes <spherical rigidity of maximal total volume> under the correct normalization.

\b[Under the literal trace bound, the assertion is false in dimension four.] Take the <Riemannian product> $M=S^2(r)\times S^2(r)$ with $r^2=1/(\sqrt6\,k)$. Its <Ricci curvature> is $r^{-2}g=\sqrt6\,kg\geq kg$, and
$$
\operatorname{Vol}M=(4\pi r^2)^2=\frac{8\pi^2}{3k^2}=\operatorname{Vol}S_k^4.
$$
But a mixed tangent two-plane has <sectional curvature> zero, whereas a factor plane has curvature $\sqrt6\,k$. Thus this manifold is not the round sphere despite having the literal hypotheses.