Go
package main
import (
"bufio"
"fmt"
"os"
)
func isSubsequence(a, b []int) bool {
var i, j int
for i < len(a) && j < len(b) {
if a[i] == b[j] {
i++
}
j++
}
return i == len(a)
}
func main() {
in := bufio.NewReader(os.Stdin)
var n, m int
fmt.Fscan(in, &n, &m)
a, b := make([]int, n), make([]int, m)
for i := 0; i < n; i++ {
fmt.Fscan(in, &a[i])
}
for i := 0; i < m; i++ {
fmt.Fscan(in, &b[i])
}
if isSubsequence(a, b) {
fmt.Println("Yes")
} else {
fmt.Println("No")
}
}
C++
#include <iostream>
#include <vector>
using namespace std;
bool isSubsequence(const vector<int>& a, const vector<int>& b) {
size_t i = 0, j = 0;
while (i < a.size() && j < b.size()) {
if (a[i] == b[j]) {
i++;
}
j++;
}
return i == a.size();
}
int main() {
int n, m;
scanf("%d %d", &n, &m);
vector<int> a(n), b(m);
for (int i = 0; i < n; ++i) {
scanf("%d", &a[i]);
}
for (int i = 0; i < m; ++i) {
scanf("%d", &b[i]);
}
if (isSubsequence(a, b)) {
puts("Yes");
} else {
puts("No");
}
return 0;
}