Count of distinct index pair ( i , j ) such that element sum of First Array is greater | Java program for the above problem ; function to find the number of pairs satisfying the given cond . ; variables used for traversal ; count variable to store the count of possible pairs ; Nested loop to find out the possible pairs ; Check if the given condition is satisfied or not . If yes then increment the count . ; Return the count value ; Driver Code ; Size of the arrays ; Initialise the arrays ; function call that returns the count of possible pairs
class GFG { static int count_pairs ( int [ ] a , int b [ ] , int N ) { int i , j ; int count = 0 ; for ( i = 0 ; i < ( N - 1 ) ; i ++ ) { for ( j = ( i + 1 ) ; j < N ; j ++ ) { if ( ( a [ i ] + a [ j ] ) > ( b [ i ] + b [ j ] ) ) { count ++ ; } } } return count ; } public static void main ( String [ ] args ) { int N = 5 ; int a [ ] = new int [ ] { 1 , 2 , 3 , 4 , 5 } ; int b [ ] = new int [ ] { 2 , 5 , 6 , 1 , 9 } ; System . out . println ( count_pairs ( a , b , N ) ) ; } }