upper bound $\sum_{i=1}^n a_i (a_i-1)/2$ using a function of $\sum_{i=1}^n a_i$ Given $a_i \in \mathbb{N}\cup\{0\}$ and 
define 
$$
A(n) = \sum_{i=1}^n a_i (a_i-1)/2
$$
and 
$$
B(n) = \sum_{i=1}^n a_i
$$
Any ideas how to upper bound $A(n)$ as a "function" of $B(n)$? (the tighter, the better; form of this "function" does not matter). 

If $a_i =0 $ then $a_i (a_i -1 ) \leq a_i^2.$
If $a_i \geq 1$ then $a_i (a_i -1 ) \leq \left(\frac{2a_i -1}{2}\right)^2 =\left( a_i -\frac{1}{2}\right)^2\leq a_i^2 $
hence
$$2A(n) \leq \sum_i a_i^2 \leq \left(\sum_i a_i \right)^2 =B(n) ^2$$
so 
$$A(n)\leqslant \frac{B(n)^2}{2}.$$
