Description

Little Nastya has a hobby, she likes to remove some letters from word, to obtain another word. But it turns out to be pretty hard for her, because she is too young. Therefore, her brother Sergey always helps her.

Sergey gives Nastya the word t and wants to get the word p out of it. Nastya removes letters in a certain order (one after another, in this order strictly), which is specified by permutation of letters' indices of the word ta1... a|t|. We denote the length of word x as |x|. Note that after removing one letter, the indices of other letters don't change. For example, if t = "nastya" and a = [4, 1, 5, 3, 2, 6] then removals make the following sequence of words "nastya"  "nastya"  "nastya"  "nastya"  "nastya"  "nastya"  "nastya".

Sergey knows this permutation. His goal is to stop his sister at some point and continue removing by himself to get the word p. Since Nastya likes this activity, Sergey wants to stop her as late as possible. Your task is to determine, how many letters Nastya can remove before she will be stopped by Sergey.

It is guaranteed that the word p can be obtained by removing the letters from word t.

Input

The first and second lines of the input contain the words t and p, respectively. Words are composed of lowercase letters of the Latin alphabet (1 ≤ |p| < |t| ≤ 200 000). It is guaranteed that the word p can be obtained by removing the letters from word t.

Next line contains a permutation a1, a2, ..., a|t| of letter indices that specifies the order in which Nastya removes letters of t (1 ≤ ai ≤ |t|, allai are distinct).

Output

Print a single integer number, the maximum number of letters that Nastya can remove.

Examples
input
ababcba
abb
5 3 4 1 7 6 2
output
3
input
bbbabb
bb
1 6 3 4 2 5
output
4
Note

In the first sample test sequence of removing made by Nastya looks like this:

"ababcba"  "ababcba"  "ababcba"  "ababcba"

Nastya can not continue, because it is impossible to get word "abb" from word "ababcba".

So, Nastya will remove only three letters.

题意:按照数字的顺序删除第一个字符串中的字符,问能不能得到子串是第二个字符串

解法:二分,反正是按照顺序来的,一个个尝试绝对不行,使用二分降低计算次数,然后记录需要删除的字符,对第二个字符进行比较,符合要求就减少范围,不符合范围就加大范围

 #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <iostream> // C++头文件,C++完全兼容C
#include <algorithm> // C++头文件,C++完全兼容C
#define fre freopen("in.txt","r",stdin) //以文件代替控制台输入,比赛时很常用,能缩短输入测试样例的时间
#define INF 0x3f3f3f3f
#define inf 1e60
using namespace std; // C++头文件,C++完全兼容C
#define N 200005 // 宏定义
#define LL long long //宏定义 LL dp[N][][]; //第一个[]表示走到第几格,第二个[]表示第几行(0 或 1),第三个[]表示已经进行了几次换道
//其实第一个[]完全可以省略,因为进行操作的都是当前路段和前1个路段
int a[N],b[N];
struct P
{
int x,y,ans;
}H[N];
int ans;
bool cmd(P a,P b)
{
return a.ans<b.ans;
}
//记录每条道的值
int vis[N];
int main()
{
string s1,s2;
cin>>s1>>s2;
for(int i=;i<s1.size();i++)
{
cin>>a[i];
}
int l=,r=s1.size()-;
while(l<=r)
{
ans=;
int mid=(l+r)/;
memset(vis,,sizeof(vis));
for(int i=;i<=mid;i++)
{
vis[a[i]-]=;
}
for(int i=;i<s1.size();i++)
{
if(vis[i]==&&s2[ans]==s1[i])
{
ans++;
}
}
if(ans==s2.size())
{
l=mid+;
}
else
{
r=mid-;
}
}
cout<<l<<endl;
return ;
}

最新文章

  1. HTML5 Boilerplate - 让页面有个好的开始
  2. ASP.NET Aries 开源开发框架:开发指南(一)
  3. iOS 创建framework &amp; bundle 主要配置
  4. background-size对background-position的影响
  5. pthread_exit
  6. RTOS
  7. Uploadify在MVC中使用方法案例(一个视图多次上传单张图片)
  8. Ugly Windows
  9. winform中相对路径和绝对路径的获取
  10. Windows开发中一些常用的辅助工具
  11. Binary Tree Level Order Traversal II 解答
  12. spring+mybatis之声明式事务管理初识(小实例)
  13. Python文本数据互相转换(pandas and win32com)
  14. Python-每日习题-0009-time
  15. Spring Boot 2程序不能加载 com.mysql.jdbc.Driver 问题
  16. 控制台获取AngularJS某个元素的Scope
  17. Spring Boot 容器选择 Undertow 而不是 Tomcat
  18. Ubuntu下快速部署安装 Nginx + PHP + MySQL 笔记
  19. 20155230 2016-2017-2《Java程序设计》第六周学习总结
  20. Educational Codeforces Round 46 (Rated for Div. 2)

热门文章

  1. 项目Beta冲刺(团队1/7)
  2. 程序编写安全代码——sendto和recvfrom的大坑
  3. C++11 条件变量
  4. mysql 发生系统错误1067
  5. ActiveMQ 安全认证
  6. chdir函数的使用【学习笔记】
  7. 书写优雅的shell脚本(插曲)- ed编辑器
  8. http的安全方法和幂等性
  9. AutoIt: WinGetClassList可以把当前窗口所有的handle全部列出来
  10. YUIDoc的使用方法小结