Advertisement
Guest User

Untitled

a guest
Mar 28th, 2020
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.37 KB | None | 0 0
  1. OPT:
  2. a_1 + a_2 + ... + a_n/2 = a_sum
  3. b_1 + b_2 + ... + b_n/2 = b_sum
  4.  
  5. stuck:
  6. c_1 + c_2 + ... + c_n/2 = c_sum
  7. d_1 + d_2 + ... + d_n/2 = d_sum
  8.  
  9. WLOG assumptions:
  10. ordered by rating: a_i < a_i+1, b_i < b_i+1, etc.
  11. unique solution
  12. a_sum < b_sum, c_sum < d_sum
  13.  
  14. assume no such swap can decrease |d_sum - c_sum|
  15. i.e. for all 1<=i, j<=n/2
  16. | d_sum - d_i + c_j - (c_sum - c_j + d_i) | > d_sum - c_sum
  17.  
  18. so
  19.  
  20. 1. d_sum - d_i + c_j - (c_sum - c_j + d_i) > d_sum - c_sum
  21. OR
  22. 2. d_sum - d_i + c_j - (c_sum - c_j + d_i) < c_sum - d_sum
  23.  
  24. from 1:
  25. A: c_j - d_i > 0 => c_j > d_i
  26. OR
  27. from 2:
  28. B: c_j - d_i < c_sum - d_sum
  29.  
  30.  
  31.  
  32. By definition, d_sum-c_sum > b_sum-a_sum
  33.  
  34. Note that no such swap can decrease |b_sum - a_sum| either.
  35.  
  36. So we also get
  37. C: a_j - b_i > 0 => a_j > b_i
  38. OR
  39. D: a_j - b_i < a_sum - b_sum
  40.  
  41. for all j, i
  42.  
  43. Let's start to pick relevant p, q
  44.  
  45. p is the first index that c_p != a_p
  46. q is the first index that d_q != b_q
  47.  
  48. Case 1
  49. c_p < a_p
  50. and
  51. d_q < b_q
  52.  
  53. This is not possible. min(c_p, d_q) would have caused an earlier conflict, so one of p or q would not have been the first index.
  54.  
  55. By symmetry,
  56. Case 4
  57. c_p > a_p
  58. and
  59. d_q > d_q
  60. is also impossible.
  61.  
  62. Leaving just
  63. Case 2
  64. c_p < a_p
  65. and
  66. d_q > b_q
  67.  
  68. OR
  69.  
  70. Case 3
  71. c_p > a_p
  72. and
  73. d_q < b_q
  74.  
  75. Note that by symmetry, we actually only need to solve one of these 2 cases.
  76.  
  77. Case 2
  78. subcase AC:
  79. c_p > d_q
  80. a_p > b_q
  81.  
  82. Then a_p > c_p > d_q > b_q
  83.  
  84. This is not possible. element b_q must appear somewhere in c, d, but we already said this is the first difference. As the unique minimum of those 4 elements, b_q would have caused an earlier difference. Contradiction!
  85.  
  86. subcase BD:
  87. a_p - b_q < a_sum - b_sum
  88. c_p - d_q < c_sum - d_sum
  89. With c_p < a_p and d_q > b_q,
  90.  
  91. c_p - d_q < a_sum - b_sum < c_sum - d_sum
  92.  
  93. Recall above that by definition, our stuck solution d_sum - c_sum > b_sum - a_sum. But this is a contradiction with the second part of the above inequality!
  94.  
  95. subcase AD (and BC by symmetry)
  96. c_p > d_q
  97. a_p - b_q < a_sum - b_sum
  98. With c_p < a_p and d_q > b_q =>
  99.  
  100. c_p - d_q < a_p - b_q < a_sum-b_sum
  101.  
  102. Note that c_p - d_q is still positive and less than a_sum - b_sum. So, this means that making the same swap would actually improve OPT. Contradiction! OPT is not optimal.
  103.  
  104. All cases reached contradiction, meaning that our strategy will reach the correct solution and won't get "stuck" anywhere! QED
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement