ConorMcGregor's blog

By ConorMcGregor, history, 8 years ago, In English

I was trying to solve Codeforces 141C Queue. even after looking at editorial and submissions of other coders i couldn't reach in a state of solving this problem. I didn't understand what is the idea behind implementation and and how we reach to the conclusion whether solution exist or not. Thanks in Advance.

  • Vote: I like it
  • -11
  • Vote: I do not like it

| Write comment?
»
8 years ago, # |
Rev. 5   Vote: I like it 0 Vote: I do not like it

Just done it, the tutorial's description is really short so I am going to ignore it...

So first, after we input the list of people standing in the queue, we have to sort it in increasing order of the amount of people taller than him. We are doing this to see whether there is a point at the queue where there is simply impossible to have that much people taller than the guy at (position)i. By greedy, each a[i] at i is set to its' minimum, so if even in the best case a[i] > i, we cannot find a person to stand in that place, right? In this case we would have to flag that such queue is impossible to construct and output -1.

Great, now we have the queue constructed, but what about their height? So far I have only came up with a pretty straight forward way, We are going to construct their height in a vector. Starting from the first guy, each of them are inserted into the height vector at position i-a[i]. (We are talking about sorted position i.) We can do this since the n is rather small (3000) so insert won't result in a long compilation time, and what the people at the back see doesn't affect what people at the front see, so insert and updating the vector won't cause problem thus ensuring there is always a[i] people taller than the guy at position i.

Now, we have two vectors of the order queue and height, all we have to do is output them and it's done.

My code: http://codeforces.com/contest/141/submission/18782179

AC, 62ms.

(Welp I am bad in expressing my ideas in English, you are welcomed to ask anything that I didn't expressed clearly enough.)