#P8147. [JRKSJ R4] Salieri
[JRKSJ R4] Salieri
Description
Salieri discovered patterns for making music. He represents the -th pattern as a string , and the initial beauty of this pattern is .
Now Salieri wants to produce pieces of music. Each time, his inspiration can be represented as a string . Let be the number of occurrences of in . Then the final beauty of the piece made using pattern is .
Of course, Salieri wants the final beauty to be as large as possible, but he found that under this inspiration, the top most beautiful pieces have already been made by Mozart, so he can only make the -th most beautiful piece. Please output this final beauty.
Formal statement: Given strings , each with a weight . For each of the queries, you are given a string and a constant . Let be the number of occurrences of in . Find the -th largest value among .
Input Format
The first line contains two integers .
The next lines each contain a string and an integer .
The next lines each contain a string and an integer .
Output Format
Output one integer per line, representing the answer.
4 2
ab 2
a 2
ba 2
b 1
bbaba 2
aab 1
4
4
15 4
ba 18
cbc 74
aac 54
ba 77
a 66
c 96
cdb 47
dc 45
cb 62
db 88
dda 93
db 34
b 81
acd 100
da 80
bcaacbbdcbabcda 4
bccac 3
abdbaca 5
cbdaaaacaaca 3
124
66
77
108
Hint
Let be the total length of all .
| Special property | Score | |||
|---|---|---|---|---|
| None | ||||
| None | ||||
For of the testdata, , .
At all times, is of the same order as . Only four characters will appear in and . , and .

Translated by ChatGPT 5
京公网安备 11011102002149号