Longest arithmetic progression in a sorted array