I’m trying to understand the approach of the editorial, but a little confused and would appreciate more explanation for this pseudocode. Editorial: FROGV - Editorial - editorial - CodeChef Discuss
Pre-Compute ( A , K ):
sort(A,A+N); //Sorted in Decreasing Order of X .
Max_Distance[A[0].ind]=A[0].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[0].ind]=A[0].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)
Thanks!