#BS0000416. Trò chơi xóa ký tự (String Game)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Trò chơi xóa ký tự (String Game)
String Game
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Sergey wants the word to be obtainable from by deletions. His sister Nastya deletes positions in the prescribed permutation , where . Positions refer to the original word and are numbered from . Sergey may stop her and delete additional letters himself. Determine the largest number of deletions she can perform before he intervenes. Initially can be obtained from without reordering letters.
Input
The first two lines contain and , respectively. The third line contains integers in deletion order.
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
ababcba
abb
5 3 4 1 7 6 2
Output 1
3
Explanation 1
Deleting positions leaves abba; positions form abb. Deleting position next leaves bba, which cannot form abb. Hence .
Input 2
bbbabb
bb
1 6 3 4 2 5
Output 2
4
Explanation 2
The first four deletions leave the two letters at positions , both b. The next deletion leaves only one letter, so the answer is .