欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1722D.Line
Line
There are people in a horizontal line, each looking either to the left or the right. Each person counts the number of people in the direction they are looking. The value of the line is the sum of each person's count.
For example, in the arrangement LRRLL, where L stands for a person looking left and R stands for a person looking right, the counts for each person are , and the value is .
You are given the initial arrangement of people in the line. For each from to , determine the maximum value of the line if you can change the direction of at most people.
Input
The input consists of multiple test cases. The first line contains an integer () — the number of test cases. The description of the test cases follows.
The first line of each test case contains an integer () — the length of the line.
The following line contains a string consisting of characters, each of which is either L or R, representing a person facing left or right, respectively — the description of the line.
It is guaranteed that the sum of over all test cases does not exceed .
Please note that the answer for some test cases won't fit into 32-bit integer type, so you should use at least 64-bit integer type in your programming language (like long long for C++).
Output
For each test case, output space-separated non-negative integers — the maximum value of the line if you can change the direction of at most people for each from to , inclusive.
Note
In the first test case:
- : change the direction of person to make the line
RLR. The total value is . - : change the direction of people to make the line
RLL. The total value is . - : change the direction of people to make the line
RLL. The total value is . Note that you have to change the direction of at most people.
In the second test case, it is optimal to only change the direction of the first person for all from to (that is, make the line RRRLL).
Samples
6
3
LLR
5
LRRLL
1
L
12
LRRRLLLRLLRL
10
LLLLLRRRRR
9
LRLRLRLRL
3 5 5
16 16 16 16 16
0
86 95 98 101 102 102 102 102 102 102 102 102
29 38 45 52 57 62 65 68 69 70
44 50 54 56 56 56 56 56 56
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |