欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1622B.Berland Music
Berland Music
Berland Music is a music streaming service built specifically to support Berland local artist. Its developers are currently working on a song recommendation module.
So imagine Monocarp got recommended songs, numbered from to . The -th song had its predicted rating equal to , where and every integer from to appears exactly once. In other words, is a permutation.
After listening to each of them, Monocarp pressed either a like or a dislike button. Let his vote sequence be represented with a string , such that means that he disliked the -th song, and means that he liked it.
Now the service has to re-evaluate the song ratings in such a way that:
- the new ratings still form a permutation (; each integer from to appears exactly once);
- every song that Monocarp liked should have a greater rating than every song that Monocarp disliked (formally, for all such that and , should hold).
Among all valid permutations find the one that has the smallest value of um\limits_{i=1}^n |p_i-q_i|, where is an absolute value of .
Print the permutation . If there are multiple answers, you can print any of them.
Input
The first line contains a single integer () — the number of testcases.
The first line of each testcase contains a single integer () — the number of songs.
The second line of each testcase contains integers () — the permutation of the predicted ratings.
The third line contains a single string , consisting of characters. Each character is either a or a . means that Monocarp disliked the song, and means that he liked it.
The sum of over all testcases doesn't exceed .
Output
For each testcase, print a permutation — the re-evaluated ratings of the songs. If there are multiple answers such that um\limits_{i=1}^n |p_i-q_i| is minimum possible, you can print any of them.
Note
In the first testcase, there exists only one permutation such that each liked song is rating higher than each disliked song: song gets rating and song gets rating . um\limits_{i=1}^n |p_i-q_i|=|1-2|+|2-1|=2.
In the second testcase, Monocarp liked all songs, so all permutations could work. The permutation with the minimum sum of absolute differences is the permutation equal to . Its cost is .
Samples
3
2
1 2
10
3
3 1 2
111
8
2 3 1 8 5 4 7 6
01110001
2 1
3 1 2
1 6 5 8 3 2 4 7
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |