Editorial for Doraemon và những chú khỉ khá là không liên quan


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.

Ta thấy rằng khi học sinh đến sớm thứ \(x\) đi vào lớp thì lúc đó lớp có tổng cộng \(x\) học sinh - nói cách khác, học sinh thứ \(i\) đến sớm thứ \(A_i\). Vậy ta chỉ cần sắp xếp lại mảng \(A\) và tìm vị trí ban đầu của mỗi phần tử sau khi sắp xếp.

Độ phức tạp: \(O(N \log N)\) hoặc \(O(N)\) tùy cách cài đặt.



Comments

There are no comments at the moment.