Finding a good bound for a quadratic and exponential expression of integers Suppose you have two collections of $k$ positive integers, $a_{1},\ldots,a_{k} \in \mathbb{N} \cup \{0\}$ and $b_{1},\ldots,b_{k} \in \mathbb{N} \cup \{0\}$. Suppose you have bounds on the sum $\sum_{i=1}^{k}  a_{i} \leq A$ and  $\sum_{i=1}^{k}  b_{i} \leq B$. I want to find a nice upper bound of $$ \sum_{i=1}^{k} A_{i}^{2} 2^{2B_{i}}$$ in terms of $A,B$ and $k$. The lower the better. One obvious, but rather hideous, bound is $kA^22^{2B}$. I inquire here to see if there are general advices about searching for a better bound, or perhaps someone can suggest a better bound? 
I have speculatively added a few different tags, and also the "soft-question" tag, feel free to change them.
 A: Let's define
$$F = \sum_{i=1}^k F_i = \sum_{i=1}^k A_i^2 4^{B_i}$$
Since $A_i$  and $B_i$ are positive, maximum of $F$ will occur when each individual value is as big as possible, so we can convert the inequalities to equalities
$$\sum_{i=1}^k A_i = A$$
$$\sum_{i=1}^k B_i = B$$
We can use Lagrange multipliers to try to find the extrema of $F$ under these constraints
$$L = F + \alpha \biggl(\sum_{i=1}^k A_i - A \biggr) + \beta \biggl(\sum_{i=1}^k B_i - B \biggr)$$
Taking the derivatives of $L$ with respect to $A_j$ and $B_j$ one quickly finds that the only extremum of the solution is 
$$A_i = \frac{A}{k}$$
$$B_i = \frac{B}{k}$$
In this case, the value of our function is
$$F_{eq} = k\frac{A^2}{k^2}4^{B/k} = \frac{1}{k}A^2 4^{B/k}$$
Let's compare this value to the corner case $A_{i} = (A, 0,0,0,0,0,...)$, $B_{i} = (B, 0,0,0,0,0,...)$. In the corner case, the value is simply
$$F_c = A^2 4^B$$
So our extremum is always a minimum, which means that the maximum is on the boundary of the domain. The domain boundaries in this case result in setting some of the $A_i$ and $B_i$ to zero, effectively just decreasing the size of $k$, in which case the extremum search is exactly the same, and the maximum remains on the boundary of those subdomains.
Conclusion: The maximum of the expression is the corner case, and your upper bound is simply 
$$F_c = A^2 4^B$$
Edit: I have missed one case in the original proof. I did not consider boundary cases where $A_i$ that are zero are not the same as $B_i$ that are zero.
1) Hypothesize that the maximum of $F$ is achieved when there exists at least one such $i$, for which $A_i = 0$ and $B_i \neq 0$. Then, let $j$ be some index for which $A_j$ is non-zero. It can easily be shown that the transformation $B_i^{new} = 0$ and $B_j^{new} = B_j^{old} + B_i^{old}$ would strictly increase the sum $F$ (because dependence of each term on $B_i$ is super-linear). Thus this hypothesis is wrong.
2) Similarly, we can refute the hypothesis that the maximum of $F$ is achieved when there exists at least one such $i$, for which $A_i \neq 0$ and $B_i = 0$.
Thus, we have proven that the maximum must reside in the case where the supports of $A_i$ and $B_i$ are the same, which makes the original proof complete.
