Anomalous Pairs in Alert Array

Company: Hashedin_3nov

Difficulty: medium

Problem Statement

Anomalous Pairs in Alert Array Problem Description A monitoring centre records N alert levels, one per time step, as the array alert[0 .. N-1] . A pair of time steps (i, j) is anomalous when i < j and the earlier reading is more than three times the later one: alert[i] > 3 * alert[j] The comparison is strict, so a reading exactly three times the later one is not an anomaly. Count the anomalous pairs. Input Format Line 1: the integer N . Line 2: N space-separated non-negative integers, the alert levels. Output Format A single integer: the number of anomalous pairs. Examples Example 1 Input: 5 1 3 2 1 0 Output: 4 The last reading is 0 , and every earlier reading is greater than 3 * 0 = 0 , giving the four pairs (0,4) , (1,4) , (2,4) and (3,4) . No other pair qualifies -- for instance (1,3) would need 3 > 3 * 1 , which is false. Example 2 Input: 4 4 1 0 3 Output: 3 The qualifying pairs are (0,1) with 4 > 3 , (0,2) with 4 > 0 , and (1,2) with 1 > 0 . Note that (0,1) is de