I got AC sorting a vector in problem 479C, but I have no ideia why my solution fails when using a map (C++) instead. Any insights?

Revision en3, by marlonbymendes, 2016-03-19 23:29:50

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.

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en3 English marlonbymendes 2016-03-19 23:29:50 26
en2 English marlonbymendes 2016-03-19 22:23:35 12
en1 English marlonbymendes 2016-03-19 22:22:48 1219 Initial revision (published)