F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

String

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 3816    Accepted Submission(s): 1001


Problem Description
Tom has a string containing only lowercase letters. He wants to choose a subsequence of the string whose length is $k$ and lexicographical order is the smallest. It's simple and he solved it with ease.
But Jerry, who likes to play with Tom, tells him that if he is able to find a lexicographically smallest subsequence satisfying following 26 constraints, he will not cause Tom trouble any more.
The constraints are: the number of occurrences of the $i$th letter from a to z (indexed from $1$ to $26$) must in $[L_i, R_i]$.
Tom gets dizzy, so he asks you for help.
 

Input
The input contains multiple test cases. Process until the end of file.
Each test case starts with a single line containing a string $S(|S|\le 10^5)$and an integer $k(1\le k\le |S|)$.
Then $26$ lines follow, each line two numbers $L_i,R_i(0\le L_i\le R_i\le |S|)$.
It's guaranteed that $S$ consists of only lowercase letters, and $\sum |S|\le 3\times 10^5$.
 

Output
Output the answer string.
If it doesn't exist, output $-1$.
 

Sample Input
aaabbb 3 0 3 2 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
 

Sample Output
abb
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-11-22 00:34:12, Gzip enabled