Dynamic Programming21 sections · 916 units
Open in Course

Codeforces 321E Ciel and Gondola - Why QI Holds

The proof

Let cost(l,r)cost(l, r) count pairs of people in [l,r][l, r] who know each other. I need to verify QI: cost(a,c)+cost(b,d)cost(a,d)+cost(b,c)cost(a,c) + cost(b,d) \leq cost(a,d) + cost(b,c) for abcda \leq b \leq c \leq d. Consider any pair (x,y)(x, y) with x<yx < y. Count how many times it appears on each side:

1.1. Both in [b,c][b,c]: counted twice on both sides. Equal.

2.2. One in [a,b)[a,b), one in [b,c][b,c]: left has 1 (via [a,c][a,c]), right has 2 (via both). Right wins.

3.3. One in [a,b)[a,b), one in (c,d](c,d]: left has 0, right has 1 (via [a,d][a,d]). Right wins. Every pair contributes at least as much to the right side. QI holds.