Editorial for Bedao Mini Contest 10 - RAID
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.
Author:
Biết rằng: (~a_1~ + ~a_2~ + ... ~a_n~) / ~n~ = ~k~
=> ~a_1~ + ~a_2~ + ... ~a_n~ = ~n~ * ~k~
=> ~a_1~ + ~a_2~ + ... ~a_n~ - ~n~ * ~k~ = 0
=> ~a_1~ - ~k~ + ~a_2~ - ~k~ + ... ~a_n~ - ~k~ = 0
Sử dụng thuật toán chặt nhị phân dựa trên kết quả. Gọi ~K~ là trung bình cộng lượng quân lương còn lại sau khi xóa ~1~ đoạn con đi.
Vậy trung bình cộng nhỏ nhất bằng ~a_1~ + ~a_2~ + ... ~a_n~ - ~n~ * ~K~ - tổng đoạn con (~a_i~ - ~K~) lớn nhất (độ phức tạp ~O(n)~).
Chặt nhị phân sao cho trung bình cộng nhỏ nhất vừa khít với ~0~ là thỏa mãn.
Comments