시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
---|---|---|---|---|---|
2 초 (추가 시간 없음) | 512 MB | 58 | 8 | 7 | 14.000% |
You are given a string $s$ of length $n$.
A sequence of integers $t$ is an index sequence if $1 \leq t_1 < t_2 < \ldots < t_k \leq n$, where $k$ is the length of $t$.
A string corresponding to an index sequence $t$ is the the following string: $s_{t_1} s_{t_2} \ldots s_{t_k}$. Note that it is always a subsequence of $s$.
You are given an index sequence. Find the lexicographically smallest string which corresponds to some index sequence which contains the given one as a subsequence.
The first line contains the string $s$ consisting of $n$ ($1 \leq n \leq 5 \cdot 10^5$) lowercase English letters.
The second line contains a single integer $k$ ($1 \leq k \leq n$), length of $t$.
The third line contains $k$ integers $t_i$ ($1 \leq t_i \leq n$). $t$ is an index sequence.
Print a single string --- the answer to the problem.
links 2 3 4
ink
abacaba 2 4 6
aacab
pepega 2 2 6
ea
gaypride 2 6 7
aid
pogchamp 3 1 2 3
pog
frankerz 1 8
aerz
blessrng 8 1 2 3 4 5 6 7 8
blessrng
residentsleeper 4 1 3 7 15
resdeneeer