#P3500. Subsequence Verification
Subsequence Verification
Subsequence Verification
One of the tasks in the Byteotian Intelligence Test (BIT) is to cross out numbers from an initial sequence so that a given candidate sequence remains. In this problem, you are given two sequences. The first is the initial sequence, and the second is the candidate sequence. Your task is to determine whether it is possible to obtain the candidate sequence by deleting some (or possibly no) elements from the initial sequence without changing the order of the remaining elements.
Mathematically, given a sequence \(S = [S_1, S_2, \dots, S_n]\) and a candidate sequence \(T = [T_1, T_2, \dots, T_m]\), you need to decide whether there exist indices \(1 \leq i_1 < i_2 < \dots < i_m \leq n\) such that \(S_{i_j} = T_j\) for every \(1 \leq j \leq m\).
inputFormat
The input consists of two parts:
- An integer \(n\) (\(n \geq 1\)) followed by \(n\) space-separated integers representing the initial sequence.
- An integer \(m\) (\(m \geq 1\)) followed by \(m\) space-separated integers representing the candidate sequence.
outputFormat
Output a single line containing Yes
if the candidate sequence is a subsequence of the initial sequence; otherwise, output No
.
sample
5
1 2 3 4 5
3
1 3 5
Yes