Editorial for Tích lớn nhất (TS10 LQĐ, Đà Nẵng 2021)
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.
Submitting an official solution before solving the problem yourself is a bannable offence.
Đầu tiên, ta có nhận xét:
-
Tích lớn nhất của 2 phần tử là: max2 = \(max\)(tích 2 số dương lớn nhất, tích 2 số âm nhỏ nhất)
-
Tích lớn nhất của 3 phần tử là: max3 = \(max\)(tích 3 số dương lớn nhất, tích 2 số âm nhỏ nhất với 1 số dương lớn nhất)
Ta sẽ sắp xếp mảng theo thứ tự tăng dần và kết quả trên đồng nghĩa với:
-
max2 = \(max(a_{1} * a_{2}, a_{n-1} * a_n)\)
-
max3 = \(max(a_1 * a_2 * a_n, a_{n-2} * a_{n-1} * a_n)\)
Kết quả là: \(max(max2, max3)\)
Comments