AmazonOA #244
Min Time After Which the Password Becomes Irrecoverable
Estimated MediumJudge-ready
Topics (AI-labelled)Binary SearchStrings
The initial lowercase password has length n. At second t, position attackOrder[t] (1-based) is changed to *, and attackOrder is a permutation of 1..n. A damaged substring is a non-empty contiguous substring containing at least one *, counted separately by start and end positions. Find the second at which their number first reaches or exceeds m. When m=0, output 1, as specially required by the source. The source's main text mistakenly wrote the threshold as n; it is corrected according to the parameter m and both examples.
Input
The first line contains n m, the second line the password, and the third line n values attackOrder. 1≤n≤800000, 0≤m≤n(n+1)/2, the password is lowercase, and attackOrder is a permutation of 1..n.
Output
Output a single integer, the answer.
Example 1
Input:
5 10
bcced
2 3 1 4 5
Output:
2
Example 2
Input:
4 10
abcd
4 1 3 2
Output:
4
Example 3
Input:
1 0
a
1
Output:
1
Example notes
The answers are 2, 4 and 1. In the first example there are 8 damaged substrings at second 1 and 11 at second 2, which is the first time the count reaches 10.
Editorial
Loading solution…