#K55187. Capture the Optimal Photo
Capture the Optimal Photo
Capture the Optimal Photo
You are given an array of integers representing various photographic settings and a list of required counts for each type of setting. The task is to determine if there exists a contiguous subarray in which the frequency of each setting exactly corresponds to the provided required counts.
More formally, you are given two integers \( n \) and \( m \) where \( n \) is the number of settings and \( m \) is the number of possible setting types. You are also given an array \( settings[0\dots n-1] \) and an array of \( m \) integers \( required\_counts[0\dots m-1] \). The goal is to decide if there exists indices \( i \) and \( j \) (with \( 0 \le i \le j < n \)) such that for every type \( t \) (where \( 1 \le t \le m \)), the number of occurrences of \( t \) in the subarray \( settings[i\dots j] \) is exactly equal to \( required\_counts[t-1] \).
Output "YES" if such a subarray exists, otherwise output "NO".
inputFormat
The input is given from standard input in the following format:
n m s1 s2 ... sn r1 r2 ... rm
where:
- \( n \) and \( m \) are integers denoting the number of settings and the number of types respectively.
- The second line contains \( n \) integers representing the settings.
- The third line contains \( m \) integers representing the exact required count for each setting type \(1, 2, \dots, m\).
outputFormat
The output should be a single line printed to standard output containing either "YES" or "NO" (without quotes). "YES" indicates that there exists a contiguous subarray that exactly meets the required counts, and "NO" indicates otherwise.
## sample6 3
1 2 2 1 3 2
1 2 1
YES