I’m trying to understand the approach of the editorial, but a little confused and would appreciate more explanation for this pseudocode. Editorial: http://discuss.codechef.com/questions/47239/frogv-editorial
Pre-Compute ( A , K ): sort(A,A+N); //Sorted in Decreasing Order of X . Max_Distance[A.ind]=A.v+K; for(int i=1;i<N;i++) if((A[i-1].x-A[i].x)<=K) Max_Distance[A[i].ind] = Max_Distance[A[i-1].ind]; else Max_Distance[A[i].ind] = A[i].x + K; Answer ( x , y ): if ( Max_Distance[x] == Max_Distance[y] ): return "Yes" else return "No"
- What is the meaning of A+N in the sort() params?
- Max_Distance[A.ind]=A.v+k …does this mean the index of whatever frog is on the first position in the ordered plot? What is “v”?
- Still don’t understand how maximum distance is constantly being updated in the loop:
“if((A[i-1].x-A[i].x)<=K)” refers to frog at i’th position in ordered plot’s current maximum distance?
Still struggle with reading other peoples’ code too so it’s hard for me to understand what other people are doing when they don’t comment it well. Would really appreciate further explanation of this solution. (I use Java)