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

Автор obocheton, история, 4 года назад, По-английски

I was trying this problem CSES 1084.

I greedily choose the lowest sized valid apartment for every applicant (sorted both lists ascendingly).

But it turns out to be a wrong approach.

Why my approach is wrong?

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

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

Inserting the apartment sizes into the set may remove some apartments with the same size. Try using a multiset or a regular vector

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

There can be multiple apartments with same size so instead of using set use multiset. And use inbuilt lowerbound function of set as thats faster .And to remove only one element from the multiset use s.erase(it) instead of s.erase(*it) as the later will remove all occurrences of *it.

Spoiler
  • »
    »
    4 года назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    Thanks. I was searching for this one. Your code was helpful for me.

  • »
    »
    3 года назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    I am still getting tle bruh!`

    my soln

    Can you help me out?

  • »
    »
    17 месяцев назад, # ^ |
    Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

    Same solution But get tle . So, much tight bounds in simple problem . https://cses.fi/paste/f28396ef9920770e4c50e2/