5. Let $\left|x_{i}\right|<1(i=1,2, \cdots, n)$. If
$$
\begin{array}{l}
\left|x_{1}\right|+\left|x_{2}\right|+\cdots+\left|x_{n}\right| \\
=2016+\left|x_{1}+x_{2}+\cdots+x_{n}\right|,
\end{array}
$$

then the minimum value of $n$ is ( ).
(A) 2018
(B) 2017
(C) 2016
(D) 2015
5. A.

Among $x_{1}, x_{2}, \cdots, x_{n}$, let the sum of all non-negative numbers be $a$, and the sum of all negative numbers be $-b$. Then
$$
a+b=2016+|a-b| .
$$

If $a \geqslant b$, solving yields $b=1008$.
Since $\left|x_{i}\right|<1(i=1,2, \cdots, n)$, the number of negative numbers is at least 1009.
Given $a \geqslant b$, the number of non-negative numbers is also at least 1009.
Thus, $n \geqslant 1009+1009=2018$.
If $a<b$, similarly, we get $n \geqslant 2018$.
When
$$
x_{i}=-x_{i+1009}=\frac{1008}{1009}(i=1,2, \cdots, 1009)
$$

Equation (1) holds.
Therefore, the minimum value of $n$ is 2018.