Problem 869
Maximum Number of Removable Characters
Medium · 20 pts · String, Binary Search
Problem
P is a subsequence of S. REMOVABLE is a list of distinct indices of S. Find the largest K such that after deleting the characters at the first K indices of REMOVABLE, P is still a subsequence of S. If removing the first K indices keeps P a subsequence, so does removing fewer, so binary search on K, checking each candidate with a two-pointer subsequence test that skips the removed positions.
Input
The first line contains S. The second line contains P. The third line contains M, and the fourth line contains the M removable indices (0-based, distinct).
Output
Print the maximum K.
Constraints
1 <= |P| <= |S| <= 100000; 0 <= M <= |S|; P is a subsequence of S
Example input
abcacb ab 3 3 1 0
Example output
2
Explanation
With S = abcacb, P = ab and removable 3 1 0, removing indices 3 and 1 leaves the letters a, c, c, b, which still contain ab as a subsequence. Also removing index 0 would break it, so K = 2.