#C2950. Contains Maximum in Subarray
Contains Maximum in Subarray
Contains Maximum in Subarray
Given an array of integers and an integer \( k \), determine whether there exists a contiguous subarray of length at least \( k \) that contains the maximum element of the entire array. Let \( arr \) be the input array and \( M = \max(arr) \) be its maximum element. Your task is to check if there exists an index \( i \) such that the subarray \( arr[i, i+k-1] \) (if it exists) contains \( M \).
Note: A subarray is a contiguous part of the array. You should output "YES" if such a subarray exists, and "NO" otherwise.
inputFormat
The input is given via standard input and has the following format:
- The first line contains an integer \( n \) representing the number of elements in the array.
- The second line contains \( n \) space-separated integers denoting the array \( arr \).
- The third line contains an integer \( k \), which is the minimum required length of the subarray.
outputFormat
Output a single line to standard output containing "YES" if there exists a contiguous subarray of length at least \( k \) that includes the maximum element \( M \). Otherwise, output "NO".
## sample5
2 1 4 3 5
2
YES
</p>