Any hints for this particular problem?

I have been banging my head against a wall with this problem for quite some time now. The problem is, that there is a time limit, so sorting the list will probably not work, since the list can contain up to 10⁶ integers, which range from 1 to 10⁸.
I really would appreciate any hints to solve this!