PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#TP0000064. Khoảng cách lớn nhất giữa các vị trí (Maximum Width)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Khoảng cách lớn nhất giữa các vị trí (Maximum Width)
Maximum Width
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Given lowercase strings and of lengths and , a strictly increasing sequence is valid when for every . Its width is the maximum value of for . At least one valid sequence exists. Find the maximum possible width.
Input
- The first line contains integers .
- The second line contains a lowercase string of length .
- The third line contains a lowercase string of length .
Output
Print the maximum width of a valid sequence.
Subtasks
- Subtask 1 (20 points): ; both strings contain only lowercase Latin letters; is a subsequence of .
- Subtask 2 (30 points): ; both strings contain only lowercase Latin letters; is a subsequence of .
- Subtask 3 (50 points): ; both strings contain only lowercase Latin letters; is a subsequence of .
Examples
Input
5 3
abbbc
abc
Output
3
Explanation
For abbbc and abc, choose positions in . They spell abc. The consecutive gaps are and , giving width . The only a is at position and the only c is at position ; with three chosen positions, no consecutive gap can be greater than . Hence the answer is 3.