Smallest subarrays
Practice
3.1 (24 votes)
Binary search
Algorithms
C++
Problem
52% Success 5298 Attempts 30 Points 5s Time Limit 1024MB Memory 1024 KB Max Code

You are given two arrays \(A\) and \(B\) of length \(N\).

For every index \(i\) in array \(A\), find the length of the smallest subarray starting from index \(i\) such that there exist at least \(B[i]\) elements with a value greater than or equal to \(A[i]\) in the subarray. If no such subarray exists, then print \(-1\).

Input format

  • The first line contains an integer \(N\) denoting the number of elements in array \(A\) and \(B\).
  • The second line contains space-separated integers denoting the array \(A\).
  • The last line contains space-separated integers denoting the array.

Output format

Print \(N\) space-separated integers denoting the answer for every index in array \(A\).

Constraints

\(1 \le N \le 3 \times 10^5 \\ 1 \le A[i] \le 10^9 \\ 1 \le B[i] \le N\)

 

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:20
389 votes
Tags:
Easy
Points:30
17 votes
Tags:
ApprovedBinary SearchImplementationMediumOpenSorting
Points:30
6 votes
Tags:
ApprovedBinary SearchMathMediumOpenSorting