Processing math: 100%
Partition - MarisaOJ: Marisa Online Judge

Partition

Time limit: 1000 ms
Memory limit: 256 MB
Given the sequence A with n elements a1,a2,...,an. A subarray of A is defined as a sequence of consecutive elements in A. Divide the array into as many subarrays as possible such that the sum of elements in the preceding subarray is not less than the sum of elements in the succeeding subarray, and each element of array A belongs to exactly one subarray. ### Input - The first line contains a positive integer n(1n5×105). - The next line contains n elements of the array A=(a1,a2,...,an), where 1ai109. ### Output - Output a single integer, the number of subarrays that satisfy the given condition. ### Constraints - 20% of tests have n20. - 30% of tests have n1000. - The remaining 50% of tests have no additional constraints. ### Example Input: 46523 Output: 3