A key observation is that if $i$-problems are completely independent, you need to compute $n$ sums of the form
$$s=\sum_{j=1}^n\max(0,a-b_j).$$
With $a=0$ and all $b_j<0$, we get the even simpler form
$$-s=\sum_{j=1}^nb_j$$ which is a sum of $n$ terms and takes $\Omega(n)$ additions. (If parallelized, this can be lowered to $\Omega(\lg(n))$ using $n$ processors.) In the general case, you need the same amount of comparisons.
If you know a priori that only few terms are such that $b_j<a$ and you can efficiently determine which ones, then you can avoid accumulating the zeroes.
More interesting question is when $b$ is a sparse matrix. Then, two cases: if
- $a\le0$, just add the terms $\max(0, a_i-b_{ij})$ for all $i$. But if
- $a>0$, add $na_i$ and the terms $\max(-a_i,-b_{ij})$ or $-\min(a, b_{ij})$.
a[i]
it hasa[1]
. So it would only check the first element of array. I would edit it myself, but it's illegal to send edits under 6 characters. $\endgroup$