Loading...
Loading...
Loading...
A shop has n gifts with known prices. Count the pairs of different gifts whose prices add up to at most X.
Example 1
Input
5 6 1 5 3 4 2
Output
6
Six pairs fit.
Example 2
Input
2 1 1 1
Output
0
Try the problem first. Open one hint at a time.
Sort the prices, then keep one pointer at each end.
When the smallest and largest fit together, the smallest fits with every price between them.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor