Skip to content

CF1637E

Step 1

Given \(f[i]\), and a set of unordered forbidden pairs \((u,v)\). Find \(\max_{(i,j) \notin (u,v)}((f[i] + f[j]) (i + j))\).

Step 2

$$ \begin{align} (f[i] + f[j])(i + j) &= i \cdot f[i] + j \cdot f[j] + i \cdot f[j] + j \cdot f[i] \end{align} $$ The second part is really annoying. Is there something that allows a clean separation?

Observation: \(\sum{f[i]} = n\), therefore there are only \(\mathcal{O}(\sqrt{n})\) kinds of \(f[i]\).

Step 3

We can iterate over all \(f[i] + f[j]\) and store them