#BS0000468. Số ký tự có thể xóa nhiều nhất (Maximum Number of Removable Characters)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Số ký tự có thể xóa nhiều nhất (Maximum Number of Removable Characters)
Maximum Number of Removable Characters
Source: LeetCode
Version: Phuoc Hung OJ Extended
Problem Statement
Given strings and , the latter can initially be formed by deleting letters from without reordering. Positions of start at zero. An ordered list identifies deletable positions. Choose and delete the first listed original positions. Maximize while retaining as a subsequence.
Input
The first and second lines contain and . The third line contains integer . The fourth line contains integers (an empty line if ).
Output
Print the maximum number of allowed deletions.
Subtasks
- Subtask 1 (20 points): ; ; ; (); all are distinct; use lowercase English letters; is a subsequence of .
- Subtask 2 (30 points): ; ; (); all are distinct; use lowercase English letters; is a subsequence of .
- Subtask 3 (50 points): ; ; (); all are distinct; use lowercase English letters; is a subsequence of .
Examples
Input 1
abcacb
ab
3
3 1 0
Output 1
2
Explanation 1
Removing positions leaves accb; original positions form ab. Removing position as well leaves ccb, with no a. Thus .
Input 2
abcbddddd
abcd
6
3 2 1 4 5 6
Output 2
1
Explanation 2
Deleting position leaves abcddddd, starting with abcd. The next deletion removes the only c, so the maximum is .
Input 3
abcab
abc
4
0 1 2 3
Output 3
0
Explanation 3
Initially the prefix abc is available. Deleting position leaves bcab, where the only remaining a follows the only c. No deletion is possible.