# Calculate absolute difference between minimum and maximum sum of pairs in an array

#include

using namespace std;

int GetDiff(int A[], int N)

{

int SuffMaxArr[N];

SuffMaxArr[N – 1] = A[N – 1];

for (int i = N – 2; i >= 0; –i) {

SuffMaxArr[i] = max(SuffMaxArr[i + 1],

A[i + 1]);

}

int MaximumSum = INT_MIN;

for (int i = 0; i < N - 1; i++) {
if (A[i] < SuffMaxArr[i])
MaximumSum
= max(MaximumSum,
A[i] + SuffMaxArr[i]);
}
int MinimumSum = INT_MAX;
int SuffMinArr[N];
SuffMinArr[N - 1] = INT_MAX;
for (int i = N - 2; i >= 0; –i) {

SuffMinArr[i] = min(SuffMinArr[i + 1],

A[i + 1]);

}

for (int i = 0; i < N - 1; i++) {
if (A[i] < SuffMinArr[i]) {
MinimumSum = min(MinimumSum,
A[i] + SuffMinArr[i]);
}
}
return abs(MaximumSum - MinimumSum);
}
int main()
{
int arr[] = { 2, 4, 1, 3, 7, 5, 6 };
int N = sizeof(arr) / sizeof(arr[0]);
cout