310632: CF1863A. Channel
Description
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.
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 500$). The description of the test cases follows.
The first line of each test case contains three integers $n$, $a$, and $q$ ($1 \le n \le 100$, $0 \le a \le n$, $1 \le q \le 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.
OutputFor 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.
ExampleInput4 5 5 3 --+ 5 2 3 ++- 5 4 2 -+ 5 0 7 ++++-++Output
YES NO MAYBE YESNote
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".
Output
Petya是一个即时通讯软件频道的管理员。他的频道总共有n个人订阅,Petya自己不计算在内。Petya在频道上发布了一个新帖子,发布时在线的订阅者有a人。我们假设如果订阅者在线,他们总是会阅读频道中的所有帖子。之后,Petya开始监控在线订阅者的数量。他连续收到q条通知,形式为“一个订阅者下线”或“一个订阅者上线”。Petya不知道具体哪个订阅者上线或下线。保证这样的通知序列确实可能收到。Petya想知道是否所有订阅者都阅读了他的新帖子。帮助Petya判断以下三种情况中的一种:
- 不可能所有n个订阅者都阅读了帖子;
- 可能所有n个订阅者都阅读了帖子;
- 保证所有n个订阅者都阅读了帖子。
输入数据格式:
每个测试包含多个测试用例。第一行包含测试用例的数量t(1≤t≤500)。接下来是每个测试用例的描述。
每个测试用例的第一行包含三个整数n、a和q(1≤n≤100,0≤a≤n,1≤q≤100)——频道订阅者的数量、初始在线的订阅者数量和通知的数量。
每个测试用例的第二行包含一个长度为q的字符串,由字符'+'和'-'组成。如果第i个字符是'+',则表示第i条通知告诉一个订阅者上线,否则表示一个订阅者下线。
输出数据格式:
对于每个测试用例,输出一行:如果所有n个订阅者都保证阅读了帖子,则输出"YES";如果所有n个订阅者都不可能阅读帖子,则输出"NO";否则输出"MAYBE"。题目大意: Petya是一个即时通讯软件频道的管理员。他的频道总共有n个人订阅,Petya自己不计算在内。Petya在频道上发布了一个新帖子,发布时在线的订阅者有a人。我们假设如果订阅者在线,他们总是会阅读频道中的所有帖子。之后,Petya开始监控在线订阅者的数量。他连续收到q条通知,形式为“一个订阅者下线”或“一个订阅者上线”。Petya不知道具体哪个订阅者上线或下线。保证这样的通知序列确实可能收到。Petya想知道是否所有订阅者都阅读了他的新帖子。帮助Petya判断以下三种情况中的一种: - 不可能所有n个订阅者都阅读了帖子; - 可能所有n个订阅者都阅读了帖子; - 保证所有n个订阅者都阅读了帖子。 输入数据格式: 每个测试包含多个测试用例。第一行包含测试用例的数量t(1≤t≤500)。接下来是每个测试用例的描述。 每个测试用例的第一行包含三个整数n、a和q(1≤n≤100,0≤a≤n,1≤q≤100)——频道订阅者的数量、初始在线的订阅者数量和通知的数量。 每个测试用例的第二行包含一个长度为q的字符串,由字符'+'和'-'组成。如果第i个字符是'+',则表示第i条通知告诉一个订阅者上线,否则表示一个订阅者下线。 输出数据格式: 对于每个测试用例,输出一行:如果所有n个订阅者都保证阅读了帖子,则输出"YES";如果所有n个订阅者都不可能阅读帖子,则输出"NO";否则输出"MAYBE"。