Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- import math
- def search(lst, x):
- l, h = 0, len(lst) - 1
- while l <= h:
- m = (l + h) // 2
- if lst[m] == x:
- return True
- elif lst[m] < x:
- l = m + 1
- else:
- h = m - 1
- return False
- def isSub(s1, s2):
- n = len(s1)
- m = len(s2)
- i, j = 0, 0
- while i < n and j < m:
- if s1[i] == s2[j]:
- i += 1
- j += 1
- else:
- i += 1
- return j == m
- for _ in range(1):
- s1 = str(input())
- s2 = str(input())
- lst1 = []
- lst2 = []
- for i in s1:
- lst1.append(i)
- for i in s2:
- lst2.append(i)
- v = list(map(int, input().split()))
- n = len(s1)
- l, h = 0, n
- ans = -1
- while l <= h:
- m = (l + h) // 2
- lstx = lst1[:]
- for i in range(m):
- lstx[v[i] - 1] = '.'
- if isSub(lstx, lst2):
- ans = m
- l = m + 1
- else:
- h = m - 1
- print(ans)
Advertisement
Add Comment
Please, Sign In to add comment