Count number of pairs with positive sum in an array | Returns number of pairs in arr [ 0. . n - 1 ] with positive sum ; Sort the array in increasing order ; Intialise result ; Intialise first and second pointer ; Till the pointers doesn 't converge   traverse array to   count the pairs  ; If sum of arr [ i ] && arr [ j ] > 0 , then the count of pairs with positive sum is the difference between the two pointers ; Increase the count ; Driver 's Code  ; Function call to count the pairs with positive sum
def CountPairs ( arr , n ) : NEW_LINE INDENT arr . sort ( ) NEW_LINE count = 0 ; NEW_LINE l = 0 ; r = n - 1 ; NEW_LINE while ( l < r ) : NEW_LINE INDENT if ( arr [ l ] + arr [ r ] > 0 ) : NEW_LINE INDENT count += ( r - l ) ; NEW_LINE r -= 1 ; NEW_LINE DEDENT else : NEW_LINE INDENT l += 1 ; NEW_LINE DEDENT DEDENT return count ; NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT arr = [ - 7 , - 1 , 3 , 2 ] ; NEW_LINE n = len ( arr ) ; NEW_LINE print ( CountPairs ( arr , n ) ) ; NEW_LINE DEDENT