Due to the installation of a new fire alarm in ITMO server room, the system may be occasionally unavailable on the 27-th of May between 06:00 and 15:00 (UTC). ×

nik7's blog

By nik7, history, 5 weeks ago, In English,

I am talking about this question. I read the tutorial and I my approach is very much similiar to that. But I am getting tle. Here is my approach

  1. I used 2 sets, one for the skills(val) and one for the indexes(indexes). I also maintained the an ind array. ind[i] is the index of i in in the orignal array (1 based index).

  2. Now while the indexes set is not empty do the the following: Find the largest element in the val set. Find its index in the orignal array fron the ind array.

  3. Locate this index in the indexes set using find method. Then move backward and forward and delete k elements both from the indexes and val set. Assign the teams in alternate fashion. I didn't delete while traversing. First I traversed the set k elements left and right and stored all the indexes in a vector. Then I traversed the vector and delete from the indexes and val set.

This is the submission. Since every element is deleted and traversed only once its time complexity is NlogN. Plese help what is wrong with this submission

UPD : Finally solved the problem. The mistake I was comitting was using find() instead of set.find()

  • Vote: I like it  
  • +2
  • Vote: I do not like it  

5 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by nik7 (previous revision, new revision, compare).