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

Автор scope_, история, 3 года назад, По-английски

Problem

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

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

hmmm... i think if you could give us the link to the problems judge, it would've been a lot easier... :)

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

An efficient way of solving this problem(instead of O(n)). Can you provide the link to the ques so that i can verify my ans?

My Code

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

    Sorry, this problem appears in the OA of ByteDance So, I don't have a link. But Could you PLz Explain your Approach Thanks.

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

      Instead of allocating memory for each second i.e O(n) we can directly make a jump of i seconds. we choose that value of i after which the maxm(m1,m2) changes.

      we will remove i' units i.e sum of n natural numbers upto i — (already removed units upto prev. seconds).

      i is calculated using quadratic equation i*(i+1)/2=difference reqd.