- 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
- 70 lines of Go from the credited upstream file 925B.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 "bufio"5 . "fmt"6 "io"7 "sort"8)9 1011func CF925B(_r io.Reader, _w io.Writer) {12 in := bufio.NewReader(_r)13 out := bufio.NewWriter(_w)14 defer out.Flush()15 16 var n, x1, x2 int17 Fscan(in, &n, &x1, &x2)18 a := make([]struct{ v, i int }, n)19 for i := range a {20 Fscan(in, &a[i].v)21 a[i].i = i + 122 }23 sort.Slice(a, func(i, j int) bool { return a[i].v > a[j].v })24 25 swap := false26 f := func() bool {27 for i, p := range a {28 if p.v > (x1-1)/(i+1) {29 for j := i + 1; j < n; j++ {30 if a[j].v > (x2-1)/(j-i) {31 Fprintln(out, "Yes")32 if !swap {33 Fprintln(out, i+1, j-i)34 for _, p := range a[:i+1] {35 Fprint(out, p.i, " ")36 }37 Fprintln(out)38 for _, p := range a[i+1 : j+1] {39 Fprint(out, p.i, " ")40 }41 } else {42 Fprintln(out, j-i, i+1)43 for _, p := range a[i+1 : j+1] {44 Fprint(out, p.i, " ")45 }46 Fprintln(out)47 for _, p := range a[:i+1] {48 Fprint(out, p.i, " ")49 }50 }51 return true52 }53 }54 return false55 }56 }57 return false58 }59 if f() {60 return61 }62 x1, x2, swap = x2, x1, true63 if f() {64 return65 }66 Fprint(out, "No")67}68 6970