Minimum Loss 1

  • + 0 comments

    Proof of correctness of looking at min diff of only consecutive numbers (when their positions satisfy the requirement) in a sorted price list: suppose that we have prices p1<p2<p3 where we assume that p1,p3 is the optimal pair. In the original list p1 must appear after p3, and since p1,p2 is not chosen as the optimal pair despite p2-p1<p3-p1, p2 must appear after p1. Then we know that p2 appears after p3 and p3-p2<p3-p1, and we should've chosen p2,p3 instead, contradiction.