Finding the maximum value for $\left\lceil\frac{b-x}{2}\right\rceil + \left\lceil\frac{x-a}{2}\right\rceil$ 
I have given two numbers $a$ and $b$, we have to choose an optimal $x$ (with $a\le x\le b$) such that
$$\left\lceil\frac{b-x}{2}\right\rceil + \left\lceil\frac{x-a}{2}\right\rceil = \text{maximum}$$

I thought the optimal way to choose $x$ we are such that it got canceled from both sides.
Therefore, maximum sum will be
$$\left\lceil \frac{b}{2}\right\rceil + \left\lceil-\frac{a}{2}\right\rceil$$
It works for some cases, but what am I missing?
 A: Short answer: choose $x$ which is very slightly larger than $a$. (more precisely: an order of magnitude smaller than the fractional parts of both $-a$ and $b-a$ will suffice.)

Without loss of generality take $a=0$ (since if $(a',b',x')=(0,b-a,x-a)$ then $\left\lceil\frac{b-x}{2}\right\rceil + \left\lceil\frac{x-a}{2}\right\rceil = \left\lceil\frac{b'-x'}{2}\right\rceil + \left\lceil\frac{x'-a'}{2}\right\rceil $), so that $0\leq x\leq b$. It will be convenient to write $B=\lfloor\frac{b}{2}\rfloor$ for the integer part of $\frac{b}{2}$.
If $b=2B$ is an even integer, then $\left\lceil \frac{b-x}{2}\right\rceil + \left\lceil\frac{x}{2}\right\rceil =  \frac{b}{2}+\left\lceil\frac{-x}{2}\right\rceil + \left\lceil\frac{x}{2}\right\rceil$, which is $B+1$ for any $x$ which is not an even integer, and this is clearly the maximum (or there is a formal argument similar to the other case).
If $b=2B+\epsilon$ is not even integer, then for all sufficiently small $x$ (explicitly, $x<\epsilon$) we have $\left\lceil\frac{b-x}{2}\right\rceil=\left\lceil\frac{b}{2}\right\rceil=B+1$, and thus $\left\lceil \frac{b-x}{2}\right\rceil + \left\lceil\frac{x}{2}\right\rceil = B+2$.
We claim this is the maximum. Indeed, in general $y\leq \lceil y\rceil<y+1$, so for any $x$ (not necessarily small):
$$ \frac{b-x}{2} + \frac{x}{2} \leq \left\lceil \frac{b-x}{2}\right\rceil + \left\lceil\frac{x}{2}\right\rceil < \frac{b-x}{2} + \frac{x}{2} + 2$$
$$ \frac{b}{2} \leq \left\lceil \frac{b-x}{2}\right\rceil + \left\lceil\frac{x}{2}\right\rceil < \frac{b}{2} + 2$$
But by definition, $B$ is the largest integer such that $B+2<\frac{b}{2}+2$, this proves optimality.
