Блог пользователя marlonbymendes

Автор marlonbymendes, история, 9 лет назад, По-английски

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

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

WA submission (using map): 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.

  • Проголосовать: нравится
  • -6
  • Проголосовать: не нравится

»
9 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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

»
9 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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

»
9 лет назад, # |
  Проголосовать: нравится +5 Проголосовать: не нравится

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.