marlonbymendes's blog

By marlonbymendes, history, 8 years ago, In English

Problem link: http://codeforces.com/contest/479/problem/C

AC submission (sorting a vector): http://codeforces.com/contest/479/submission/16772060

WA submission (using map): http://codeforces.com/contest/479/submission/16772083

I used a greedy approach in the WA submission. It's possible to take any exam scheduled to the day A before day A. Suppose that the in the final solution for the problem all the exams scheduled to the day A are taken before A. If this is true, the last exam will be completed in the greatest number B, such that B is smaller than A, within all elements in the set of exams scheduled to the day A. This greedy step translates to code like this:

auto at = mp.find(a);
if(at != mp.end()) {
    at->second = max(at->second, b);
}
else {
    mp[a] = b;
}

If this step is not possible, consider the first element C > A such that mp[C] < mp[A], so I cant take exam C in the day mp[C]. So the next minimum value available is C. This step is done in nom-increasing order of A. But I got WA with this solution and have no ideia why.

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

»
8 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by marlonbymendes (previous revision, new revision, compare).

»
8 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by marlonbymendes (previous revision, new revision, compare).

»
8 years ago, # |
  Vote: I like it +5 Vote: I do not like it

Suppose there are two exams in day C, one for which b < mp[A] and one for which b > mp[A]. You only keep the maximum b, so you will miss the first one.