AppleOA #1
Ignore Sections
估计简单可在线判题
考点(AI 标注)模拟/实现原地数组
From left to right, delete each complete interval that starts with a 1 and ends at the first 0 after it, including both ends. Meeting another 1 inside an interval does not reset its start. A trailing segment with no closing 0 is kept in full, and all other elements are kept in their original order; also return the sum of the kept elements. The outputs of original examples 2 and 4 contradict the statement and explanation; this site corrects them according to the explicit statement.
输入格式
The first line contains n, and the second line contains n integers. 1≤n≤100000, −10⁹≤element≤10⁹.
输出格式
The first line is the number of kept elements m; the second line contains m integers (an empty line when m=0); the third line is the sum, which needs a 64-bit integer.
样例 1
输入:
9
6 1 7 0 2 5 6 1 3
输出:
6
6 2 5 6 1 3
23
样例 2
输入:
8
4 0 6 1 4 6 1 2
输出:
8
4 0 6 1 4 6 1 2
24
样例 3
输入:
9
0 6 1 1 9 1 3 0 2
输出:
3
0 6 2
8
样例说明
Example 1: delete 1, 7, 0 and keep 6, 2, 5, 6, 1, 3, sum 23. Example 2: neither of the two later 1s has a following 0, so the whole array is kept, sum 24; the original output dropped elements. Example 3: delete the interval from the first 1 to the following 0, keeping 0, 6, 2, sum 8; the original output omitted the 6.