Editorial for TLE '17 Contest 2 P2 - Unlucky Numbers


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.

Author: ChaSiu

The solution uses a prefix sum array. Create an int array arr of size 1000001, and ensure that all values in that array are set to 0. Then, for each unlucky number ui, set arr[ui] to 1.

Now you may create a prefix sum array with the same size as arr (1000001). In the PSA, psa[0]=0, and for all 1i1000000, psa[i]=psa[i1]+arr[i]. The PSA shows you that for an apartment with top floor j, there will be psa[j] floors removed.

Time Complexity: O(K+N)


Comments

There are no comments at the moment.