question is Problem - B - Codeforces
I came across this solution and cannot understand the if part
Submission #76435784 - Codeforces
print arr[k+i] for every odd i
After sorting u need to pick up first and last element,then 2nd and 2nd last and so on…
because the difference between the first and last element will be maximum and it will decrease as we choose further elements…
use a while loop to understand it easily…
int i = 0,j = n-1;
while(i<=j)
{
if(i == j)
{
v.push_back(a[i]);
break;
}
v.push_back(a[i]);
v.push_back(a[j]);
i++;
j–;
}
now just print it in the reverse order because the max difference values are at front and it decreases along the array.
5 Likes