Editorial for TSS '19 CC P2 - Counting Pairs
Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist. 
Submitting an official solution before solving the problem yourself is a bannable offence.
                Submitting an official solution before solving the problem yourself is a bannable offence.
Authors:
For 60% of the points, you can simply brute force each pair of integers.
For the last 40% of the points, store a 0-indexed sorted array . For each integer 
 in 
, binary search for the rightmost position of 
, where 
 is equal to 
. If such an integer exists, then the position of 
 will be the solution for the integer 
.
Note: c++ has a method called upper_bound which can help you to solve this in fewer lines.
Comments