CF1352D.Alice, Bob and Candies
普及-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
There are n candies in a row, they are numbered from left to right from 1 to n. The size of the i-th candy is ai.
Alice and Bob play an interesting and tasty game: they eat candy. Alice will eat candy from left to right, and Bob — from right to left. The game ends if all the candies are eaten.
The process consists of moves. During a move, the player eats one or more sweets from her/his side (Alice eats from the left, Bob — from the right).
Alice makes the first move. During the first move, she will eat 1 candy (its size is a1). Then, each successive move the players alternate — that is, Bob makes the second move, then Alice, then again Bob and so on.
On each move, a player counts the total size of candies eaten during the current move. Once this number becomes strictly greater than the total size of candies eaten by the other player on their previous move, the current player stops eating and the move ends. In other words, on a move, a player eats the smallest possible number of candies such that the sum of the sizes of candies eaten on this move is strictly greater than the sum of the sizes of candies that the other player ate on the previous move. If there are not enough candies to make a move this way, then the player eats up all the remaining candies and the game ends.
For example, if n=11 and a=[3,1,4,1,5,9,2,6,5,3,5], then:
- move 1: Alice eats one candy of size 3 and the sequence of candies becomes [1,4,1,5,9,2,6,5,3,5].
- move 2: Alice ate 3 on the previous move, which means Bob must eat 4 or more. Bob eats one candy of size 5 and the sequence of candies becomes [1,4,1,5,9,2,6,5,3].
- move 3: Bob ate 5 on the previous move, which means Alice must eat 6 or more. Alice eats three candies with the total size of 1+4+1=6 and the sequence of candies becomes [5,9,2,6,5,3].
- move 4: Alice ate 6 on the previous move, which means Bob must eat 7 or more. Bob eats two candies with the total size of 3+5=8 and the sequence of candies becomes [5,9,2,6].
- move 5: Bob ate 8 on the previous move, which means Alice must eat 9 or more. Alice eats two candies with the total size of 5+9=14 and the sequence of candies becomes [2,6].
- move 6 (the last): Alice ate 14 on the previous move, which means Bob must eat 15 or more. It is impossible, so Bob eats the two remaining candies and the game ends.
Print the number of moves in the game and two numbers:
- a — the total size of all sweets eaten by Alice during the game;
- b — the total size of all sweets eaten by Bob during the game.
一行中有 n 颗糖果,从左到右依次编号为 1 到 n。第 i 颗糖果的大小为 ai。
Alice 和 Bob 玩一个有趣又美味的游戏:吃糖果。Alice 从左往右吃,Bob 从右往左吃。当所有糖果都被吃完时,游戏结束。
游戏由若干轮(moves)组成。在每一轮中,当前玩家从自己一侧吃一颗或多颗糖果(Alice 从左侧吃,Bob 从右侧吃)。
Alice 先手。第一轮中,她只吃一颗糖果(大小为 a1)。之后,双方轮流进行——即 Bob 进行第二轮,接着 Alice 第三轮,然后 Bob 第四轮,依此类推。
在每一轮中,当前玩家需计算本轮所吃糖果的总大小。一旦该总和严格大于对方在上一轮中所吃糖果的总大小,当前玩家即停止进食,本轮结束。换言之,在每一轮中,玩家应吃下最少数量的糖果,使得本轮所吃糖果的大小之和严格大于对方上一轮所吃糖果的大小之和。若剩余糖果不足以满足该条件,则该玩家吃掉所有剩余糖果,游戏结束。
例如,若 n=11 且 a=[3,1,4,1,5,9,2,6,5,3,5],则:
- 第 1 轮:Alice 吃一颗大小为 3 的糖果,糖果序列变为 [1,4,1,5,9,2,6,5,3,5]。
- 第 2 轮:Alice 上轮吃了 3,因此 Bob 必须吃 至少 4。Bob 吃一颗大小为 5 的糖果,糖果序列变为 [1,4,1,5,9,2,6,5,3]。
- 第 3 轮:Bob 上轮吃了 5,因此 Alice 必须吃 至少 6。Alice 吃三颗糖果,总大小为 1+4+1=6,糖果序列变为 [5,9,2,6,5,3]。
- 第 4 轮:Alice 上轮吃了 6,因此 Bob 必须吃 至少 7。Bob 吃两颗糖果,总大小为 3+5=8,糖果序列变为 [5,9,2,6]。
- 第 5 轮:Bob 上轮吃了 8,因此 Alice 必须吃 至少 9。Alice 吃两颗糖果,总大小为 5+9=14,糖果序列变为 [2,6]。
- 第 6 轮(最后一轮):Alice 上轮吃了 14,因此 Bob 必须吃 至少 15。但已无法满足,故 Bob 吃掉剩余两颗糖果,游戏结束。
请输出游戏的总轮数,以及两个数值:
- a —— Alice 在整局游戏中所吃糖果的总大小;
- b —— Bob 在整局游戏中所吃糖果的总大小。
输入格式
The first line contains an integer t (1≤t≤5000) — the number of test cases in the input. The following are descriptions of the t test cases.
Each test case consists of two lines. The first line contains an integer n (1≤n≤1000) — the number of candies. The second line contains a sequence of integers a1,a2,…,an (1≤ai≤1000) — the sizes of candies in the order they are arranged from left to right.
It is guaranteed that the sum of the values of n for all sets of input data in a test does not exceed 2⋅105.
第一行包含一个整数 t(1≤t≤5000)—— 输入中测试用例的数量。接下来是 t 个测试用例的描述。
每个测试用例由两行组成。第一行包含一个整数 n(1≤n≤1000)—— 糖果的数量。第二行包含一个整数序列 a1,a2,…,an(1≤ai≤1000)—— 按从左到右顺序排列的糖果尺寸。
保证所有测试用例中 n 的值之和不超过 2⋅105。
输出格式
For each set of input data print three integers — the number of moves in the game and the required values a and b.
对于每组输入数据,输出三个整数——游戏中的移动步数以及所需的值 a 和 b。
输入输出样例
输入#1
7 11 3 1 4 1 5 9 2 6 5 3 5 1 1000 3 1 1 1 13 1 2 3 4 5 6 7 8 9 10 11 12 13 2 2 1 6 1 1 1 1 1 1 7 1 1 1 1 1 1 1
输出#1
6 23 21 1 1000 0 2 1 2 6 45 46 2 2 1 3 4 2 4 4 3
输入解题思路,AI测评打分。不知道怎么写?