Find $y$ such that it makes $\sum_{i=1}^{n}n_i |y-i|$ takes the minimum value. In the above expression, $n_i\ge1$, $i\gt0$.
I can tell you the answer of $y$ might be the weighted median of $i's$, however I don't know how to prove it.
First example: $1,1,2,2,2$, median is $2$, $y=2$, min is $2$.
Second example: $1,1,2,2,3,3,3,3$, median is $2.5$, min is $6$.
Edit
From the comment, here is the proof for $n_i=1$, and it is for real numbers.
It lead me to think maybe my problem can also extended to real number case.
Let $f(y) = \sum_{i=1}^{i=n}n_i |y-i|$. As the sum of continuous functions, $f$ is continuous. Note that on the intervals $(i,i+1), f(y)$ is linear. Where the slope is negative, $f$ is decreasing and where it is positive, $f$ is increasing. So what you need to do is locate the value $y = i$ where the slope of $f$ switches sign.
For a particular value of $y$, that slope is $\sum_{i<y}n_i - \sum_{i>y}n_i$. Thus the minimum will be at the value of $i$ where that difference switches from negative to positive.