Equal subarrays
Practice
3.9 (35 votes)
Advanced data structures
Data structures
Segment trees
Problem
82% Success 14480 Attempts 30 Points 2s Time Limit 256MB Memory 1024 KB Max Code

You are given an array of \(N\) non-negative integers \([A_1, A_2, A_3, ... , A_N]\), and a non-negative integer \(K\). A subarray is an array composed of a contiguous block of original array elements. You can perform the following operation on a subarray:

Increase each element of this subarray by a non-negative number such that the total sum of all the increments does not exceed \(K\). You must make all the elements of this subarray equal.

Determine the maximum length of a subarray in which all the elements can be made equal by performing the mentioned operation.

Input format

  • First line: An integer \(N\) denoting the number of elements in the array
  • Second line: An integer \(K\)
  • Third line: \(N\) space-separated integers where \(A_i\) denotes the elements of the array

Output format

Print the maximum length of a subarray in which all the elements can be made equal by performing the operation.

Constraints

\(1 ≤ N ≤ 10^5\\ 0 ≤ K ≤ 10^9\\ 1 ≤ Ai ≤ 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
9 votes
Tags:
Advanced Data StructuresData StructuresEasyFenwick TreeSegment Trees
Points:30
8 votes
Tags:
Bit ManipulationEasyFenwick TreeSegment TreesSieve