COPS - Editorial

I have used prefix sum or something is better than that?

There is a relatively obvious answer which for speed doesn’t depend on the number of houses at all and doesn’t involve populating an array with likely-redundant entries. Sort the cop houses - O(N\log N) - then step through these - O(N) - to find the safe ranges.


lim = 100
for _ in range(int(input())):
    # input
    m,x,y = map(int, input().split())
    cops = sorted( map(int, input().split()) ) # read and sort
    # process
    rng = x*y        # the range of each cop
    hse = 1          # the next available house safe from the cops reviewed so far
    safe = 0         # count of safe houses
    for cop in cops:
        if cop-rng > hse:
            # there is a gap in cop coverage
            safe += cop-rng-hse 
        hse = cop+rng+1 # current cop cannot reach this
    if hse<=lim:
        # some safe houses at the end too
        safe += lim-hse+1
    # report
    print(safe)

what is wrong with this??
https://www.codechef.com/viewsolution/21204870