FlyingElephant's blog

By FlyingElephant, history, 9 months ago, In English

I was solving this problem. But I keep getting RTE on test2 and I dont understand why.

My idea is selecting the smallest 2*n elements by putting them into a set. Then I use two pointers on the array sorted by coordinate component in order to get the system of nested segments. No wonder what goes wrong with that.

SUBMISSION

  • Vote: I like it
  • 0
  • Vote: I do not like it

»
9 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Nobody?

»
9 months ago, # |
  Vote: I like it 0 Vote: I do not like it

try to put all variable outside the main() function

»
9 months ago, # |
  Vote: I like it +1 Vote: I do not like it

Let's analize this testcase:

1
1 3
1 -5
2 -6
3 -5

Your multiset will look like this s = {-6, -5}
For i = 0 and j = 2, both weights are -5, so you are going in the first if and erasing -5 and then trying to erase it again, but there was only one -5 in the multiset.

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

    yes maybe its something like this. I have to ensure the instances in the multiset are different. Thx for the hint

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

    but wait.. in the multiset there must be 2 times -5. right?

    • »
      »
      »
      9 months ago, # ^ |
        Vote: I like it 0 Vote: I do not like it
      if((ll) s.size() > 2*n){
      	ll big = *(--s.end());
      	s.erase(s.find(big));
      }
      

      You are deleting the biggest value in multiset when it size is bigger than 2 * n, so no, there is only one -5 at the end in it.