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?
Difference between en2 and en3, changed 26 character(s)
Problem link:↵
http://codeforces.com/contest/479/problem/C↵

AC submission (
using mapsorting a vector): ↵
http://codeforces.com/contest/479/submission/16772060↵

WA submission (
sorting a vectorusing 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)