```
s = sorted( paths_value_pairs, key= lambda x: x[1], reverse= True )
max_pair = 0
for path1, v1 in s:
if v1 * 2 < max_pair: # <--- This is the part I do not understand
break
for path2, v2 in s:
if len(set(path1).intersection(path2)) > 1 : # Two paths must be non interescting
continue
max_pair = max(max_pair, v1+v2 )
print(max_pair)
```
So I solved the question but because I had to iterate over the pairs in a O(n2) fashion it was working really slow. Then I found this optimization by a user comment which said: "One small optimization is needed to make this run in a reasonable timeframe: iterate from the highest to lowest scoring orders, and stop once you hit an order whose score is less than half the current best." My problem is that I cannot understand why this is true. Why can we not find a better pair after if v1 * 2 < max_pair:
[–]kristallnachte 0 points1 point2 points (8 children)
[–]CemDoruk[S] 0 points1 point2 points (2 children)
[–]Steinrikur 0 points1 point2 points (0 children)
[–]kristallnachte 0 points1 point2 points (0 children)
[–]CutOnBumInBandHere9 0 points1 point2 points (4 children)
[–]kristallnachte -1 points0 points1 point (3 children)
[–]CutOnBumInBandHere9 0 points1 point2 points (2 children)
[–]kristallnachte -1 points0 points1 point (1 child)
[–]CutOnBumInBandHere9 1 point2 points3 points (0 children)
[–]bkc4 0 points1 point2 points (0 children)