← CSES Better

Variation

ZCO · 2015 · Zonal Computing Olympiad · ZCO15002

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 · two-pointers · pair-counting

The organizer’s problem statement is available at the official source link.

difference threshold

Count pairs outside a value band

A pair qualifies when the sorted values differ by at least K, on either side.

sorted x_i <= x_jdifference = x_j - x_iqualifies when difference >= K
  1. 1

    Sort values

    Sort the sequence.
  2. 2

    Find threshold boundary

    For each smaller endpoint, locate the first value at least K larger.
  3. 3

    Count qualifying pairs

    Count all values from that boundary to the end and avoid counting each pair twice.
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.