Alex Varghese edited q5.tex  about 10 years ago

Commit id: 05695836522a8bf5539c69f937174de289433f22

deletions | additions      

       

Let us look at the case where the optimal solution requires that you use two gifts per person. Our algorithm will always use the two largest gifts to satisfy the lowest person so in our case the worst optimal solution will be the one that uses the largest and smallest gift left to satify the next person. The reason this case is the worst is because our algorithm will have a lot of waste since $a_j+a_j+1-s_j$ will be as large as possible. That means we are wasting some money on this particular person.  So for an example if we have 8 gifts left and 4 people left the optimal solution in the worst case is:(remember both arrays are sorted from largest to smallest)  a1 and a8 ==> s1  a2 and a7 ==> s2  a3 and a6 ==> s3  a4 and a5 ==> s4  Now using our algorithm we get:  a1 and a2 ==> s4  a3 and a4 ==> s3  a5,a6,a7,a8 ==> s2???  The first two lines are obviously true and can be easily verified. In the worst case the last line would not be satisfied and we would be left with only half the people being satisfied.