X Subarrays
Practice
5 (1 votes)
Binary search
Algorithms
Problem
54% Success 955 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code
You are given an array \(A\) of length \(N\) sorted in non-decreasing order and an integer \(X\). Find the number of subarrays such that the sum of the minimum and maximum element of that subarray is less than or equal to \(X\).
Input Format:
- The first line contains an integer \(T\), which denotes the number of test cases.
- The first line of each test case contains two integers, \(N\) and \(X\).
- The next line of each test case contains \(N\) space-separated integers, elements of array \(A\).
Output Format:
For each test case, print the number of subarrays such that the sum of the minimum and maximum element of that subarray is less than or equal to \(X\).
Constraints:
\(1 \leq T \leq 10 \\ 1 \leq N \leq 10^5 \\ 1 \leq A[i], X \leq 10^5\)
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
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
7 votes
Tags:
AlgorithmsBinary search treeBinary SearchTrie
Points:30
4 votes
Tags:
MathAlgorithmsBinary Search
Points:30
7 votes
Tags:
Medium
Editorial
Login to unlock the editorial