#GD0000146. Bài toán trên bảng (Task On The Board)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Bài toán trên bảng (Task On The Board)
Task On The Board
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
A lowercase string has been processed by deleting some characters and rearranging the remaining characters into an unknown string of length . For each position you are given : the sum of distances over all positions where is alphabetically larger than .
Find any string consistent with the data. A solution is guaranteed to exist.
Input
The first line contains the lowercase string . The second line contains . The third line contains integers .
Output
Print a lowercase string of length , made from available occurrences in , that satisfies every distance sum .
Subtasks
- Subtask 1 (20 points): ; ; ; ; a solution exists.
- Subtask 2 (30 points): ; ; ; ; a solution exists.
- Subtask 3 (50 points): ; ; ; ; a solution exists.
Examples
Input
abba
3
1 0 1
Output
aba
Explanation
The string aba can be formed from abba. The first and last a are each one position away from the larger character b, so ; the middle b has no larger character, so .