CF1863A.Channel
入门
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Petya is an administrator of a channel in one of the messengers. A total of n people are subscribed to his channel, and Petya is not considered a subscriber.
Petya has published a new post on the channel. At the moment of the publication, there were a subscribers online. We assume that every subscriber always reads all posts in the channel if they are online.
After this, Petya starts monitoring the number of subscribers online. He consecutively receives q notifications of the form "a subscriber went offline" or "a subscriber went online". Petya does not know which exact subscriber goes online or offline. It is guaranteed that such a sequence of notifications could have indeed been received.
Petya wonders if all of his subscribers have read the new post. Help him by determining one of the following:
- it is impossible that all n subscribers have read the post;
- it is possible that all n subscribers have read the post;
- it is guaranteed that all n subscribers have read the post.
Petya 是某即时通讯软件中一个频道的管理员。该频道共有 n 位订阅者,而 Petya 本人不被视为订阅者。
Petya 在频道中发布了一条新帖子。在发布时刻,有 a 位订阅者在线。我们假设:每位订阅者只要处于在线状态,就一定会阅读频道中的所有帖子。
此后,Petya 开始监控在线订阅者人数。他依次收到 q 条通知,每条通知的形式为“一位订阅者下线”或“一位订阅者上线”。Petya 并不知道具体是哪一位订阅者上线或下线。题目保证所给的通知序列确实是可能发生的。
Petya 想知道:是否所有订阅者都已阅读了这条新帖子?请帮助他判断以下三种情况之一:
- 所有 n 位订阅者都已阅读该帖子是不可能的;
- 所有 n 位订阅者都已阅读该帖子是可能的;
- 所有 n 位订阅者都已阅读该帖子是确定无疑的。
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤500). The description of the test cases follows.
The first line of each test case contains three integers n, a, and q (1≤n≤100, 0≤a≤n, 1≤q≤100) — the number of subscribers of the channel, the initial number of subscribers online, and the number of notifications.
The second line of each test case contains a string of length q, consisting of characters '+' and '-'. The i-th of these characters is '+', if the i-th notification tells that a subscriber goes online, and it is '-' otherwise.
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤500)。随后是各测试用例的描述。
每个测试用例的第一行包含三个整数 n、a 和 q(1≤n≤100,0≤a≤n,1≤q≤100)——分别表示频道的订阅者总数、初始在线订阅者数以及通知数量。
每个测试用例的第二行包含一个长度为 q 的字符串,仅由字符 '+' 和 '-' 组成。其中第 i 个字符为 '+' 表示第 i 条通知告知一名订阅者上线,为 '-' 则表示一名订阅者下线。
输出格式
For each test case, output a single line: "YES" if all n subscribers are guaranteed to have read the post, "NO" if it is impossible for all n subscribers to have read the post, and "MAYBE" otherwise.
对于每个测试用例,输出一行:如果所有 n 个订阅者都保证已阅读该帖子,则输出 "YES";如果所有 n 个订阅者都不可能已阅读该帖子,则输出 "NO";否则输出 "MAYBE"。
输入输出样例
输入#1
4 5 5 3 --+ 5 2 3 ++- 5 4 2 -+ 5 0 7 ++++-++
输出#1
YES NO MAYBE YES
说明/提示
In the first test case, there are 5 out of 5 subscribers online in the very beginning, so they will all read the post no matter what. The answer is "YES".
In the second test case, the number of subscribers online becomes 4 after the first two notifications, next someone goes offline, and thus the fifth subscriber has no chance of reading the post. It is impossible for all the subscribers to read the post, so the answer is "NO".
In the third test case, on the one hand, the same person may have gone offline and online (in this case only 4 out of 5 subscribers have read the post), on the other hand, the last notification may have told that the fifth subscriber has gone online (in this case all subscribers have read the post). We cannot deduce which of the two holds, so the answer is "MAYBE".
In the fourth test case, there have to be five subscribers online after all the notifications. All of them will read the post, so the answer is "YES".
在第一个测试用例中,最开始就有 5 名订阅者在线,因此无论发生什么,他们都会阅读该帖子。答案为 “YES”。
在第二个测试用例中,前两次通知后在线订阅者人数变为 4,随后又有一人下线,因此第五名订阅者将没有机会阅读该帖子。不可能让所有订阅者都阅读该帖子,故答案为 “NO”。
在第三个测试用例中,一方面,同一人可能先下线再上线(此时仅有 4 名订阅者阅读了该帖子);另一方面,最后一次通知也可能表明第五名订阅者已上线(此时所有订阅者均阅读了该帖子)。我们无法判断上述哪种情况成立,因此答案为 “MAYBE”。
在第四个测试用例中,所有通知发送完毕后必须有五名订阅者在线。他们都将阅读该帖子,因此答案为 “YES”。
输入解题思路,AI测评打分。不知道怎么写?