Let $F=∑i=1$ to $N((abs(A[i]-X))^P \mod K)\mod K$
$A[1..N]$ is an array with $N$ elements, the problem is to find $X$ such that the above summation F maximized where $X$ can take any value from the given array $A[1....N]$. $A[1..N]$ and $k$ are given.
$1 \leq N \leq 100000$.
$1 \leq P \leq 100$.
$1 \leq K \leq 1000000009$.
$1 \leq A[i] \leq 2000$.
Sample case: suppose $A[1...3]$={$3,1,2$} and $P=1$ and $K=10$.
Then ans=$3$ either by choosing $X=3$ or $X=1$.
I am interested in finding the maximum value of above summation F without brute force approach i.e by using all possible values of $X$.