Count of pairs from arrays A and B such that element in A is greater than element in B at that index | C # program to find the maximum count of values that follow the given condition ; Function to find the maximum count of values that follow the given condition ; Initializing the max - heap for the array A [ ] ; Adding the values of A [ ] into max heap ; Adding the values of B [ ] into max heap ; Counter variable ; Loop to iterate through the heap ; Comparing the values at the top . If the value of heap A [ ] is greater , then counter is incremented ; Driver code
using System ; using System . Collections . Generic ; class GFG { static int check ( int [ ] A , int [ ] B , int N ) { List < int > pq1 = new List < int > ( ) ; List < int > pq2 = new List < int > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { pq1 . Add ( A [ i ] ) ; } for ( int i = 0 ; i < N ; i ++ ) { pq2 . Add ( B [ i ] ) ; } pq1 . Sort ( ) ; pq1 . Reverse ( ) ; pq2 . Sort ( ) ; pq2 . Reverse ( ) ; int c = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( pq1 [ 0 ] > pq2 [ 0 ] ) { c ++ ; pq1 . RemoveAt ( 0 ) ; pq2 . RemoveAt ( 0 ) ; } else { if ( pq2 . Count == 0 ) { break ; } pq2 . RemoveAt ( 0 ) ; } } return c ; } static public void Main ( ) { int [ ] A = { 10 , 3 , 7 , 5 , 8 } ; int [ ] B = { 8 , 6 , 2 , 5 , 9 } ; int N = A . Length ; Console . WriteLine ( check ( A , B , N ) ) ; } }