Problem link: ↵
http://codeforces.net/contest/479/problem/C↵
↵
AC submission (using map): ↵
http://codeforces.net/contest/479/submission/16772060↵
↵
WA submission (sorting a vector): ↵
http://codeforces.net/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.↵
↵
http://codeforces.net/contest/479/problem/C↵
↵
AC submission (using map): ↵
http://codeforces.net/contest/479/submission/16772060↵
↵
WA submission (sorting a vector):
http://codeforces.net/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.↵
↵