Repovive
  • Dashboard
  • Ranking
  • Submissions
  • Discussion
  1. Contests
  2. Starter Round 9
  3. 25C

My submissions

/
/
/
/

Announcements

My submissions

/
/
/
/

Announcements

Solve
Author

Compress the smallest version first

Compressing file iii requires bib_ibi​ units of free space. Writing its compressed version consumes bib_ibi​ units, and deleting the original releases aia_iai​ units. The free space therefore increases by ai−bi>0a_i-b_i>0ai​−bi​>0.

Consider the remaining file with the smallest bib_ibi​. If it does not fit, no remaining file fits. If it fits, compressing it immediately cannot hurt: move it to the front of any successful order. Every file that originally preceded it now has more free space available, and after those files the amount of free space is unchanged.

Repeating this argument shows that sorting by bib_ibi​ in nondecreasing order is optimal. Ties may be resolved arbitrarily.