Rodionno's blog

By Rodionno, 14 months ago, In Russian

I came up with a simple task, but i can't solve it faster than O(n ^ 2). So I thought that maybe someone will help me with this.

Task: given an array of numbers, you need to find segment [l, r] where value sum(l, r) * len(l, r) will be the biggest for all pairs of l, r such as 1 <= l <= r <= n. sum(l, r) = a[l] + a[l + 1] + ... + a[r], len(l, r) = r - l + 1. 1 <= n <= 10^5, -10^9 <= a[i] <= 10^9

UPD: probably it can be solved with some kind of cht or maybe li chao tree. Also it's intresting to firstly find segment with biggest sum and then try to expand it.

  • Vote: I like it
  • 0
  • Vote: I do not like it

»
14 months ago, # |
  Vote: I like it +26 Vote: I do not like it

The answer is [1, n]

»
14 months ago, # |
  Vote: I like it +1 Vote: I do not like it

With -10^9 <= a[i] <= 10^9 constraint, it is really interesting task