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

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

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

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

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

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.