Skip to content

Editorial for Sòng bạc

Sòng bạc

Problem code: olpicpc158 Group: Uncategorized Points: 1,500 points
Limits
1.0 s, 256 MB
AC rate
16.7%
Solvers
4
Read the editorial only when you are stuck, and do not copy code from it. Please respect the problem author and the editorialist: submitting an official solution before solving the problem yourself is a bannable offence.

Với mỗi chỉ số j (1 \le j \le m), ta tiến hành tính tổng độ chênh lệch giữa tất cả các cặp người chơi đối với con số thứ j.

Tiến hành sắp xếp giá trị các con số thứ j của n người theo thứ tự tăng dần. Duyệt qua với mỗi chỉ số i (1 \le i \le n), ta tính tổng độ chênh lệch giữa phần tử thứ i với các phần tử nhỏ hơn (đứng trước phần tử i do đã sắp xếp). Có thể sử dụng Tổng tiền tố (Prefix Sum) để tính toán trong O(n).

Độ phức tạp: O(n.m).

Comments