- Translate each rule into one explicit state update.
- Maintain the invariant after every processed item.
- Return the accumulated state once all relevant input has been handled.
Code notes
- 57 lines of Go from the credited upstream file 314D.go.
- The implementation visibly relies on sequence storage.
- No explicit loop blocks detected.
Complexity
Count the number and nesting of passes over the input, then include the maintained containers in the memory estimate.
Check the problem constraints before deciding whether this complexity will pass.
Use this to learn the idea, then write your own version.
1package main2 3import (4 . "fmt"5 "io"6 "slices"7 "sort"8)9 1011func cf314D(in io.Reader, out io.Writer) {12 var n, x, y int13 Fscan(in, &n)14 type point struct{ x, y int }15 a := make([]point, n)16 for i := range a {17 Fscan(in, &x, &y)18 a[i] = point{x + y, y - x}19 }20 slices.SortFunc(a, func(a, b point) int { return a.x - b.x })21 22 type pair struct{ min, max int }23 pre := make([]pair, n+1)24 pre[0].min = 2e925 pre[0].max = -2e926 for i, p := range a {27 pre[i+1].min = min(pre[i].min, p.y)28 pre[i+1].max = max(pre[i].max, p.y)29 }30 suf := make([]pair, n+1)31 suf[n] = pre[0]32 for i := n - 1; i >= 0; i-- {33 y := a[i].y34 suf[i].min = min(suf[i+1].min, y)35 suf[i].max = max(suf[i+1].max, y)36 }37 38 ans := sort.Search(2e9, func(mx int) bool {39 l := 040 for i, p := range a {41 if i+1 < n && p.x == a[i+1].x {42 continue43 }44 for p.x-a[l].x > mx {45 l++46 }47 if max(pre[l].max, suf[i+1].max)-min(pre[l].min, suf[i+1].min) <= mx {48 return true49 }50 }51 return false52 })53 Fprintf(out, "%.1f", float64(ans)/2)54}55 5657