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

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

how can i start thinking about problem like this http://codeforces.com/problemset/problem/478/D?

can anyone explain the solution ?

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

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

First observation is that the maximum height h is greatest h satisfying h*(h + 1)/2 <= r + g.

let's say total = h*(h + 1)/2, then if you take g green balls and (total — g) red balls, then number of ways of arranging them is same as number of ways of expressing (total — g) as sum of numbers (order doesn't matter) less than h. and the ans is summation of that sum for all g.

Here is my code

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

Wait, this is trivial O(N).