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.

Authors: jsumabat

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 arr. For each integer x in arr, binary search for the rightmost position of y, where y is equal to M-x. If such an integer exists, then the position of y will be the solution for the integer x.

Note: c++ has a method called upper_bound which can help you to solve this in fewer lines.


Comments

There are no comments at the moment.