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

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

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

can anyone explain the solution ?

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

»
8 лет назад, скрыть # |
 
Проголосовать: нравится 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

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

Wait, this is trivial O(N).