  We consider a Brownian motion (BM) $x(\tau)$ and its maximal value $x_{\max}
= \max_{0 \leq \tau \leq t} x(\tau)$ on a fixed time interval $[0,t]$. We study
functionals of the maximum of the BM, of the form ${\cal
O}_{\max}(t)=\int_0^t\, V(x_{\max} - x(\tau)) {\rm d} \tau$ where $V(x)$ can be
any arbitrary function and develop various analytical tools to compute their
statistical properties. These tools rely in particular on (i) a "counting
paths" method and (ii) a path-integral approach. In particular, we focus on the
case where $V(x) = \delta(x-r)$, with $r$ a real parameter, which is relevant
to study the density of near-extreme values of the BM (the so called density of
states), $\rho(r,t)$, which is the local time of the BM spent at given distance
$r$ from the maximum. We also provide a thorough analysis of the family of
functionals ${T}_{\alpha}(t)=\int_0^t (x_{\max} - x(\tau))^\alpha \, {\rm
d}\tau$, corresponding to $V(x) = x^\alpha$, with $\alpha$ real. As $\alpha$ is
varied, $T_\alpha(t)$ interpolates between different interesting observables.
For instance, for $\alpha =1$, $T_{\alpha = 1}(t)$ is a random variable of the
"area", or "Airy", type while for $\alpha=-1/2$ it corresponds to the maximum
time spent by a ballistic particle through a Brownian random potential. On the
other hand, for $\alpha = -1$, it corresponds to the cost of the optimal
algorithm to find the maximum of a discrete random walk, proposed by Odlyzko.
We revisit here, using tools of theoretical physics, the statistical properties
of this algorithm which had been studied before using probabilistic methods.
Finally, we extend our methods to constrained BM, including in particular the
Brownian bridge, i.e., the Brownian motion starting and ending at the origin.
