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

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

Given an array $$$a$$$, you have to divide this array into maximum numbers of continous subarrays that the sum of a subarray is greater or equal to every subarrays that come after it. $$$1 \le n \le 5 \times 10^5, 1 \le a_i \le 10^9$$$.

Example:

Input

4
6 5 2 3

Output

3

A possible solutions:

6 | 5 | 2 3

Can anyone help me with this problems? I only came up with $$$O(n^2)$$$ solution. Thanks in advance!

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

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

Can you share problem link

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

nvm

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

I have a weird idea. Unsure if it works. Let's add all elements to a set each element is currently a subarray. If there's an element $$$x$$$ with an element $$$y$$$ after it such that $$$x \lt y$$$ then we remove $$$y$$$ from the set and add it to $$$x$$$. Can someone provide a case where this fails?