obocheton's blog

By obocheton, history, 4 years ago, In English

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?

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

| Write comment?
»
4 years ago, # |
  Vote: I like it +1 Vote: I do not like it

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

»
4 years ago, # |
Rev. 3   Vote: I like it +1 Vote: I do not like it

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 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

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

  • »
    »
    3 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    I am still getting tle bruh!`

    my soln

    Can you help me out?

    • »
      »
      »
      2 years ago, # ^ |
      Rev. 2   Vote: I like it -23 Vote: I do not like it

      same doubt

    • »
      »
      »
      9 months ago, # ^ |
        Vote: I like it +3 Vote: I do not like it

      Because in set or multi_set the lower_boud syntax is different from the normal vector and syntax will be set.lower_bound(val);

  • »
    »
    16 months ago, # ^ |
    Rev. 2   Vote: I like it 0 Vote: I do not like it

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