CF1792B.Stand-up Comedian
普及-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Eve is a beginner stand-up comedian. Her first show gathered a grand total of two spectators: Alice and Bob.
Eve prepared a1+a2+a3+a4 jokes to tell, grouped by their type:
- type 1: both Alice and Bob like them;
- type 2: Alice likes them, but Bob doesn't;
- type 3: Bob likes them, but Alice doesn't;
- type 4: neither Alice nor Bob likes them.
Initially, both spectators have their mood equal to 0. When a spectator hears a joke he/she likes, his/her mood increases by 1. When a spectator hears a joke he/she doesn't like, his/her mood decreases by 1. If the mood of a spectator becomes negative (strictly below zero), he/she leaves.
When someone leaves, Eve gets sad and ends the show. If no one leaves, and Eve is out of jokes, she also ends the show.
Thus, Eve wants to arrange her jokes in such a way that the show lasts as long as possible. Help her to calculate the maximum number of jokes she can tell before the show ends.
Eve 是一名初出茅庐的单口喜剧演员。她的首场演出总共只吸引了两名观众:Alice 和 Bob。
Eve 准备了共计 a1+a2+a3+a4 个笑话,按类型分组如下:
- 类型 1:Alice 和 Bob 都喜欢;
- 类型 2:Alice 喜欢,但 Bob 不喜欢;
- 类型 3:Bob 喜欢,但 Alice 不喜欢;
- 类型 4:Alice 和 Bob 都不喜欢。
初始时,两位观众的情绪值均为 0。当一位观众听到一个他/她喜欢的笑话时,其情绪值增加 1;当听到一个他/她不喜欢的笑话时,其情绪值减少 1。若某位观众的情绪值变为负数(严格小于零),他/她便会离场。
一旦有人离场,Eve 就会感到难过并立即结束演出。如果无人离场,而 Eve 又讲完了所有笑话,她也会结束演出。
因此,Eve 希望以某种顺序安排她的笑话,使得演出尽可能持久。请帮她计算在演出结束前最多能讲多少个笑话。
输入格式
The first line contains a single integer t (1≤t≤104) — the number of testcases.
The only line of each testcase contains four integers a1,a2,a3,a4 (0≤a1,a2,a3,a4≤108; a1+a2+a3+a4≥1) — the number of jokes of each type Eve prepared.
第一行包含一个整数 t(1≤t≤104)—— 测试用例的数量。
每个测试用例仅有一行,包含四个整数 a1,a2,a3,a4(0≤a1,a2,a3,a4≤108;a1+a2+a3+a4≥1)—— 分别表示 Eve 准备的四种类型笑话的数量。
输出格式
For each testcase, print a single integer — the maximum number of jokes Eve can tell before at least one of the spectators leaves or before she runs out of jokes.
对于每个测试用例,输出一个整数——Eve 在至少一名观众离场或她讲完所有笑话之前,最多能讲的笑话数量。
输入输出样例
输入#1
4 5 0 0 0 0 0 0 5 2 5 10 6 3 0 0 7
输出#1
5 1 15 7
说明/提示
In the first testcase, Eve only has jokes of the first type. Thus, there's no order to choose. She tells all her jokes, both Alice and Bob like them. Their mood becomes 5. The show ends after Eve runs out of jokes.
In the second testcase, Eve only has jokes of the fourth type. Thus, once again no order to choose. She tells a joke, and neither Alice, nor Bob likes it. Their mood decrease by one, becoming −1. They both have negative mood, thus, both leave, and the show ends.
In the third testcase, first, Eve tells both jokes of the first type. Both Alice and Bob has mood 2. Then she can tell 2 jokes of the third type. Alice's mood becomes 0. Bob's mood becomes 4. Then 4 jokes of the second type. Alice's mood becomes 4. Bob's mood becomes 0. Then another 4 jokes of the third type. Alice's mood becomes 0. Bob's mood becomes 4. Then the remaining joke of the second type. Alice's mood becomes 1. Bob's mood becomes 3. Then one more joke of the third type, and a joke of the fourth type, for example. Alice's mood becomes −1, she leaves, and the show ends.
In the fourth testcase, Eve should first tell the jokes both spectators like, then the jokes they don't. She can tell 4 jokes of the fourth type until the spectators leave.
在第一个测试用例中,Eve 只拥有第一类笑话。因此,不存在选择顺序的问题。她讲出自己所有的笑话,Alice 和 Bob 都喜欢这些笑话,两人的状态值均变为 5。当 Eve 讲完所有笑话后,演出结束。
在第二个测试用例中,Eve 只拥有第四类笑话。因此,同样不存在选择顺序的问题。她讲出一个笑话,但 Alice 和 Bob 都不喜欢它,两人的状态值均减少 1,变为 −1。由于两人的状态值均为负数,因此两人均离场,演出结束。
在第三个测试用例中,首先,Eve 先讲出两个第一类笑话,此时 Alice 和 Bob 的状态值均为 2。接着,她可以讲出 2 个第三类笑话:Alice 的状态值变为 0,Bob 的状态值变为 4。然后,她讲出 4 个第二类笑话:Alice 的状态值变为 4,Bob 的状态值变为 0。随后,她再讲出 4 个第三类笑话:Alice 的状态值变为 0,Bob 的状态值变为 4。接着,她讲出剩余的 1 个第二类笑话:Alice 的状态值变为 1,Bob 的状态值变为 3。之后,她再讲出 1 个第三类笑话和 1 个第四类笑话(例如)。此时 Alice 的状态值变为 −1,她离场,演出结束。
在第四个测试用例中,Eve 应首先讲出两位观众都喜欢的笑话,然后再讲出他们都不喜欢的笑话。她最多可讲出 4 个第四类笑话,直至观众离场。
输入解题思路,AI测评打分。不知道怎么写?