Link: Longes subsequence

Longest subsequence

String is a very useful thing and a subsequence of the same string is equally important.

Now you have a string s with length n and a string t with length m. Find out the longest subsequence in the string s so that the lexicographical order of this subsequence is strictly larger than t.

Input
two integers n, m in the first line

(All characters are lowercase letters)

The second line is a string s

The third line is a string t

1≤n,m≤1e6

Output
Output an integer representing the longest length, otherwise output -1.

样例输入1
9 3
aaabbbccc
abc
样例输出1
6
样例输入2
9 3
aaabbbccc
zzz
样例输出2
-1

Problem solving:
先占着,慢慢补

Code: