Пожалуйста, подпишитесь на официальный канал Codeforces в Telegram по ссылке https://t.me/codeforces_official. ×

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

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

Hello codeforces community.

I was trying to solve question 234C from codeforces round #145 and I could not come up with a scheme/way to solve it. So I tried looking for the editorials for this round but could not find it. Also, I looked at successful submission but could not understand the intended solution for this problem.

It would help me if you could share your approach on how you would solve this problem.

Thank You.

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

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

Consider the idea of prefix count (like prefix sums), where pre[i] counts the number of non-positive elements from index 1 to index i (inclusive). Similarly, from right to left, let suf[i] counts the number of non-negative elements from index n to index i (inclusive). Then, to find the minimum number of temperatures that need to be changed, you simply loop over all the possible values of the index k from 1 to n — 1 and minimize over pre[i] and suf[i + 1] which is exactly the number of changes to satisfy the condition given in the problem statement.

Here is my submission 56948236.