Editorial for Uparivanje


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.

Submitting an official solution before solving the problem yourself is a bannable offence.

Author: TadijaSebez

Jedno od optimalnih uparivanje za 4 broja A \leq B \leq C \leq D je uvek [(A, B), (C, D)]. Lepota ovog uparivanja je A B + C D. Pokazaćemo da uparivanja [(A, C), (B, D)] i [(A, D), (B, C)] nikada nisu bolja. \displaystyle Lepota([(A, B), (C, D)])-Lepota([(A, C), (B, D)]) = A B + C D - A C-B D = A (B - C) + D (C - B) = (A - D) (B - C) \geq 0 \displaystyle Lepota([(A, B), (C, D)])-Lepota([(A, D), (B, C)]) = A B + C D - A D - B C = A (B - D) + C (D - B) = (A - C) (B - D) \geq 0 Sada znamo da je rešenje da soritramo niz A i uparimo [(A_1, A_2), (A_3, A_4) ... (A_{N-1}, A_N)].

Vremenska složenost: O(NlogN)


Comments

There are no comments at the moment.