CF1886C.Decreasing String
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Recall that string a is lexicographically smaller than string b if a is a prefix of b (and a=b ), or there exists an index i ( 1≤i≤min(∣a∣,∣b∣) ) such that ai<bi , and for any index j ( 1≤j<i ) aj=bj .
Consider a sequence of strings s1,s2,…,sn , each consisting of lowercase Latin letters. String s1 is given explicitly, and all other strings are generated according to the following rule: to obtain the string si , a character is removed from string si−1 in such a way that string si is lexicographically minimal.
For example, if s1=dacb , then string s2=acb , string s3=ab , string s4=a .
After that, we obtain the string S=s1+s2+⋯+sn ( S is the concatenation of all strings s1,s2,…,sn ).
You need to output the character in position pos of the string S (i. e. the character Spos ).
输入格式
The first line contains one integer t — the number of test cases ( 1≤t≤104 ).
Each test case consists of two lines. The first line contains the string s1 ( 1≤∣s1∣≤106 ), consisting of lowercase Latin letters. The second line contains the integer pos ( 1≤pos≤2∣s1∣⋅(∣s1∣+1) ). You may assume that n is equal to the length of the given string ( n=∣s1∣ ).
Additional constraint on the input: the sum of ∣s1∣ over all test cases does not exceed 106 .
输出格式
For each test case, print the answer — the character that is at position pos in string S . Note that the answers between different test cases are not separated by spaces or line breaks.
输入输出样例
输入#1
3 cab 6 abcd 9 x 1
输出#1
abx