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

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

EDIT: Solved. It was not a problem with data structures, it was a logical error. I've been doing this greedy problem, and my solution fails on test case 6. For small inputs it seems to work, but for large inputs it produces strange results.

Problem: 854C - Вопросы планирования

My Solution: https://pastebin.com/MQBNBHEJ

Someone else's accepted solution: 30195313 — They used a priority_queue while I used a sorted vector. This should achieve the same result, and I do not think it is the data structure that is the problem.

Any idea what the problem might be?

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

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

Priority queue always keeps the elements in sorted order and accessing the maximum/minimum element takes O(1) complexity and then rearranges itself in O(logn). So, basically you can access max/min in O(logn) in priority queue which is required to pass all the test cases. On the other hand if you are using vector you will have to sort it every time, each sorting takes O(nlogn). For n queries it will be O(n^2logn) which causes TLE.

You can see my submission I have used set to keep elements sorted.

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

I can't see your solution