Sreekar_0125

Untitled

Oct 15th, 2023
1,000
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.01 KB | None | 0 0
  1. import sys
  2. import math
  3.  
  4.  
  5.  
  6. def search(lst, x):
  7.     l, h = 0, len(lst) - 1
  8.     while l <= h:
  9.         m = (l + h) // 2
  10.         if lst[m] == x:
  11.             return True
  12.         elif lst[m] < x:
  13.             l = m + 1
  14.         else:
  15.             h = m - 1
  16.     return False
  17.  
  18.  
  19. def isSub(s1, s2):
  20.     n = len(s1)
  21.     m = len(s2)
  22.     i, j = 0, 0
  23.     while i < n and j < m:
  24.         if s1[i] == s2[j]:
  25.             i += 1
  26.             j += 1
  27.         else:
  28.             i += 1
  29.     return j == m
  30.  
  31. for _ in range(1):
  32.     s1 = str(input())
  33.     s2 = str(input())
  34.     lst1 = []
  35.     lst2 = []
  36.     for i in s1:
  37.         lst1.append(i)
  38.     for i in s2:
  39.         lst2.append(i)
  40.     v = list(map(int, input().split()))
  41.     n = len(s1)
  42.     l, h = 0, n
  43.     ans = -1
  44.  
  45.     while l <= h:
  46.         m = (l + h) // 2
  47.         lstx = lst1[:]
  48.         for i in range(m):
  49.             lstx[v[i] - 1] = '.'
  50.         if isSub(lstx, lst2):
  51.             ans = m
  52.             l = m + 1
  53.         else:
  54.             h = m - 1
  55.     print(ans)
  56.  
Advertisement
Add Comment
Please, Sign In to add comment