Ask AI
Open a hint-first prompt in a new AI chat. Grok may ask you to confirm before sending.
Open Claude Desktopsorting · math · pair-counting
The organizer’s problem statement is available at the official source link.
sorted pairs
Count pair differences after sorting
For sorted team strengths, each pair contributes the difference between its larger and smaller strength. The table shows the aggregated pair contribution.
| Sorted strengths | Pair contribution |
|---|---|
| x1 <= x2 <= ... <= xN | xj - xi for each i < j |
| all pairs | sum over i < j of (xj - xi) |
- 1
Sort values
Sort the strengths. - 2
Use prefix sums
For each position, compute its distance from all previous values with a prefix sum. - 3
Add pair totals
Add the contributions to get the revenue across all pairs.
Tools
1
2
3
4
5
6
7
8
9
10
11
12
Draft saved locally
|12 lines, 156 charsRun output
Run your code to see output.