C # program for the above approach
using System ; using System . Collections . Generic ; class pair : IComparable < pair > { public int first , second , third ; public pair ( int first , int second , int third ) { this . first = first ; this . second = second ; this . third = third ; } public int CompareTo ( pair p ) { return this . second - p . first ; } } class GFG {