Section: 3, Score: 33, Time limit per test: 30 seconds, Memory limit per test: 512MB, Input: stdin, Output: stdout
It has been a long time since Agoji had a tour. So, he plans to visit Agodaland on his next summer vacation which has many tourist attractions and is known for tropical beaches, opulent royal palaces, ancient ruins, and ornate temples.
There are
Each city has an attractiveness rating — a letter from 'A' to 'Z' with 'Z' being the most attractive and 'A' being the least attractive.
A tour between two distinct cities,
During the tour Agoji must collect the rating of each city and arrange them in arbitrary order to form a string, which he defines as the attractiveness of the tour.
What is the most lexicographically attractive string he can attain by selecting the start and end city of the tour?
String
-
$\left|S\right| \gt \left|T\right|$ and$T$ is prefix of$S$ . -
$\left|S\right| \le \left|T\right|$ and there exists an index$i$ ($0 \le i \lt \left|S\right|$ ) such that$S_i \gt T_i$ (compared according to their ASCII codes).
For example, "poster" is lexicographically larger than "post" and "ranger" is lexicographically larger than "racecar".
The first line contains a single integer
The second line contains a string s of length
The following
Print a string t — lexicographically largest attractiveness among all tour paths.
5
BACAD
1 2
1 3
2 4
2 5
DCBA
In the sample
Following are the attractiveness of each distinct tour path after being arranged in arbitrary order.
(1, 2) -> BA
(1, 3) -> CB
(1, 4) -> BAA
(1, 5) -> DAB
(2, 3) -> ABC
(2, 4) -> AA
(2, 5) -> DA
(3, 4) -> CBAA
(3, 5) -> DCBA
(4, 5) -> ADA
Out of all the tours, the tour between cities 3 and 5, i.e., DCBA, is the most lexicographically attractive.
5
BZCZZ
1 2
1 3
2 4
2 5
ZZZ