Skip to content

P16625 GKS 2017 D Sherlock and Matrix Game

Step 1

We essentially needs to generate \(A\) and \(B\) first. Also, the matrix can have negative entries. $\(\sum_{l \le i \le r}{\sum_{a \le j \le b}{A_i B_j}} = \left(\sum_{l \le i \le r}{A_i}\right) \left( \sum_{a \le i \le b}{B_j} \right)\)$ Then we converted it into a problem on a sequence. We can find the first \(k\) largest subsequence sum for \(A_i\) and \(B_i\) (also need smallest because their may be negative numbers), then we can do a typical partial order on the sequence.