Блог пользователя fakeac

Автор fakeac, история, 8 лет назад, По-английски

Here is my code for this problem — http://codeforces.me/contest/749/problem/D from Div-2 D round #388 Here is my submission --> http://codeforces.me/contest/749/submission/23178341 My code is well commented and as per the editorial given. It is taking too much time. The complexity is O(nlog(n)). How do I optimize my code? What operation/operations are taking too long ? Please Help! Thanks in advance.

  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится

»
8 лет назад, # |
  Проголосовать: нравится +1 Проголосовать: не нравится

Dont insert every person and his bid into the set. Only insert the id of the person and his MAX bid in the set.
Now when removing people, you only have to remove a single element per unique id.
If the resultant set size=0 or 1, you have your answer.
If there are more than 1 elements in the set, find the 2nd maximum bid in the set and now binary search through the list of the maximal bid person and find a value which is just greater than the 2nd maximum bid.

Here is a code for reference-23165182