Zero subarray
Practice
4.3 (32 votes)
Algorithms
Basics of greedy algorithms
C++
Greedy algorithms
Problem
63% Success 4578 Attempts 30 Points 5s Time Limit 256MB Memory 1024 KB Max Code
Given an array A of N elements. You can apply the given operations on array A.
- Type 1: Choose an index i (1 ≤ i ≤ N) and set A[i] = A[i] - 1.
- Type 2: Choose an index i (1 ≤ i ≤ N) and set A[i] = 0.
Find the maximum length subarray in array A where all the elements in the subarray is 0 by using at most X operations of Type 1 and Y operations of Type 2.
Note
- Assume 1-based indexing.
Input
- The first line contains an integer T denoting the number of test cases.
- For each test case:
- The first line contains 3 space-separated integers N, X, Y.
- Next line contains N space-separated integers denoting the elements of array A.
Output
For each test case in a new line, print the maximum length subarray in A where all the elements in the subarray is 0.
Constraints
\(1 ≤ T ≤ 5\\ 1 ≤ N ≤ 10^5\\ 0 ≤ X ≤ 10^{14}\\ 0 ≤ Y ≤ 10^9\\ 0 ≤ A[i] ≤ 10^9\)
Submissions
Please login to view your submissions
Similar Problems
1.Closer
Points:30
3 votes
Tags:
Basics of Greedy AlgorithmsAlgorithmsGreedy Algorithms
Points:30
13 votes
Tags:
AlgorithmsBasics of Greedy AlgorithmsGreedy Algorithms
Points:30
1 votes
Tags:
AlgorithmsBasics of Greedy AlgorithmsC++Greedy Algorithms
Editorial