Mehta And Subarrays
Practice
4.3 (13 votes)
Algorithms
Approved
Binary search
Dynamic programming
Medium
Open
Sorting
Problem
72% Success 2395 Attempts 30 Points 3s Time Limit 256MB Memory 1024 KB Max Code

This time your task is simple.

Task:
Mehta has to find the longest subarray whose sum is greater than equal to zero in a given array of length** N**. After he finds out the length of longest subarray, he has to report how many subarrays of such maximum length exist that satisfy the mentioned property.

Note:
Subarray is defined as an array of contiguous numbers in a particular array. Subarray(A,B) has length (B-A+1) and consists of all numbers from index A to index B.

Input:
First Line of the input consists of a single integer N as described above. Next Line consists of N space separated integers.

Output:
In a single line, output the maximum length and number of such subarrays having maximum length separated by a single space.In case, there is no such subarray having sum greater than equal to zero, simply print "-1" without quotes.

Constraints:
N <= 10^6
Each number in the array is less than equal to 10^9 and greater than equal to -10^9 (-10^9 <= A[i] <= 10^9)

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
6 votes
Tags:
AlgorithmsApprovedBinary SearchMediumOpenSorting
Points:30
8 votes
Tags:
AlgorithmsBinary SearchHiringImplementationMediumSearchingString Manipulation
Points:30
9 votes
Tags:
AlgorithmsBinary SearchMediumOpenSorting