I will prove the time complexity is O (KN)
Consider this algorithm:
For sum(i) from 0 to k-1:
put the server i in location 0;
loop :
move the server i according to the location of server i-1 until it can not move;
move the server i-1 according to the location of server i until it can not move;
move the server i-2 according to the location of server i-1 until it can not move;
...
move the server 0 according to the location of server 1 until it can not move;
if no move happens : break;
else :return to the beginning of the loop.
}
We need to calculate the number of compare. For each server, if the result of judge(compare) is true, then the server will move one step, if the result is false, it will stop and go on to next server. So we need to calculate the numbers of "true" and "false".
For server 0, it will move for each "for" loop and for each "inner" loop, or the move will not happen.
So we assume for "for" loop, first server 0 move m1 step, second it move m2 step, finally it move mk step. For each "for" loop, there must be a "false" result of compare. So, for server 0, the total number of compare is " m1+1+m2+1+...+mk+1 = (m1+m2+...mk)+k " < N+K
Such that for the first "for" loop, there is at most m1+1 inner loops. That means for the server i, there are at most m1+1 compares whose results are "false". For the same reason, for the final "for" loop, we could get maximized number "mk+1". For the server i, we could get the total number of compares whose results are "false" is less than " m1+1+m2+1+...+mk+1" <N+K
Because for server i, the total number of compares whose results are "true" are less than N. (it is impossible for server i to move more than N steps).
Such that for server i, the total number of compares are less than N+K+N = 2N+K.
because we have k servers, so the total number of compares for all servers are less than (2N+K)*K= 2NK + K^2.
So the time complexity is O(NK).