← CSES Better

Tournament

ZCO · 2013 · Zonal Computing Olympiad · ZCO13001

Open official problem ↗
Ask AI

Open a hint-first prompt in a new AI chat. Grok may ask you to confirm before sending.

Open Claude Desktop

sorting · 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.

State table
Sorted strengthsPair contribution
x1 <= x2 <= ... <= xNxj - xi for each i < j
all pairssum over i < j of (xj - xi)
  1. 1

    Sort values

    Sort the strengths.
  2. 2

    Use prefix sums

    For each position, compute its distance from all previous values with a prefix sum.
  3. 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 chars

Run output

Run your code to see output.