text: Pair formation such that maximum pair sum is minimized | C # Program to divide the array into N pairs such that maximum pair is minimized ; After Sorting Maintain two variables i and j pointing to start and end of array Such that smallest element of array pairs with largest element ; Driver Code
code: using System ; public class GFG { static void findOptimalPairs ( int [ ] arr , int N ) { Array . Sort ( arr ) ; for ( int i = 0 , j = N - 1 ; i <= j ; i ++ , j -- ) Console . Write ( " ( " + arr [ i ] + " , ▁ " + arr [ j ] + " ) " + " ▁ " ) ; } static public void Main ( ) { int [ ] arr = { 9 , 6 , 5 , 1 } ; int N = arr . Length ; findOptimalPairs ( arr , N ) ; } }