beacons[i] = [x, y], where x is the beacon's position and y its brightness (which can be negative). The beacons are listed from left to right, with strictly increasing positions.
The score of a pair of beacons i < j is y_i + y_j + (x_j − x_i). Only pairs at a distance x_j − x_i of at most reach count.
Return the highest score among those pairs. At least one such pair is guaranteed to exist.beacons=[[0, 4], [2, -1], [3, 6], [10, 2]], reach=3 → 13
Pairs within 3: (0, 2) gives 4 − 1 + 2 = 5, (0, 3) gives 4 + 6 + 3 = 13, (2, 3) gives −1 + 6 + 1 = 6. The beacon at 10 is too far from the rest. The best is 13.
beacons=[[-5, 1], [0, 0], [4, 9]], reach=4 → 13
The gap between −5 and 0 is 5, more than 4. That leaves one pair, (0, 4): 0 + 9 + 4 = 13.
x are strictly increasingreach apartbeacons=[[0, 4], [2, -1], [3, 6], [10, 2]], reach=3
13
Run checks the first 3 tests in your browser. Submit checks all 100 tests on the server, hidden ones included.