Solution (source code)

= Solution

For maximization of $f(x)$ subject to $g_j(x)\le0$ and $h_k(x)=0$, the <Lagrangian sufficiency theorem> says: if a feasible $x^*$ globally maximizes $L(x)=f(x)-\sum_j\lambda_jg_j(x)+\sum_k\nu_kh_k(x)$, where $\lambda_j\ge0$, and $\lambda_jg_j(x^*)=0$, then $x^*$ globally maximizes $f$ over the feasible set. Indeed, at every feasible $x$,
$$
f(x)\le L(x)\le L(x^*)=f(x^*).
$$
This requires a global maximum of the <optimization Lagrangian>; a stationary point alone is not sufficient without additional concavity or another justification.

Put $q=p/(p-1)$ and $C=(\sum_i|a_i|^q)^{1/q}$. If every $a_i=0$, \b[the maximum is zero and every feasible vector is optimal]. Otherwise set
$$
x_i^*=\frac{\operatorname{sgn}(a_i)|a_i|^{q-1}}{C^{q-1}},\qquad \lambda=\frac Cp.
$$
Since $p(q-1)=q$, $\sum_i|x_i^*|^p=1$. For $g(x)=\sum_i|x_i|^p-1$, the <optimization Lagrangian> is $L(x)=\sum_i a_ix_i-\lambda g(x)$. Its <gradient> vanishes at $x^*$ because
$$
\lambda p\operatorname{sgn}(x_i^*)|x_i^*|^{p-1}=a_i.
$$
The function $\sum_i|x_i|^p$ is a <strictly convex function> for $p>1$, so $L$ is a <strictly concave function>. Its supporting-hyperplane inequality proves that this stationary point is its global maximum. <Complementary slackness> and feasibility hold, so the sufficiency theorem applies. Substitution gives
$$
\boxed{\max_{\sum_i|x_i|^p\le1}\sum_i a_ix_i=C=\left(\sum_i|a_i|^{p/(p-1)}\right)^{(p-1)/p}.}
$$
The maximizing vector is unique when $a\ne0$. It is the <norming vector for Holder inequality>, and the value is the corresponding <dual norm>.