Editorial for QCC P6 - Freedom!
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:
Subtask 1
For each query, sum the cost from each house to via simulation.
Time Complexity:
Subtask 2
For each query, use a pointer on the left and right side of to simulate the cost.
Time Complexity:
Subtask 3
For the final subtask, there are a few different solutions. One solution involves building a prefix sum array and suffix sum array where:
The answer for each query is . Note that the above solution uses -indexed arrays.
Time Complexity:
Comments