CF933E.A Preponderant Reunion
NOI/NOI+/CTSC
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
East or west, home is best. That's why family reunion, the indispensable necessity of Lunar New Year celebration, is put in such a position.
After the reunion dinner, Little Tommy plays a game with the family. Here is a concise introduction to this game:
- There is a sequence of n non-negative integers _p_1, _p_2, ..., p__n in the beginning. It is ruled that each integer in this sequence should be non-negative at any time.
- You can select two consecutive positive integers in this sequence, p__i and p__i + 1 (1 ≤ i < n), and then decrease them by their minimum (i. e. min(p__i, p__i + 1)), the cost of this operation is equal to min(p__i, p__i + 1). We call such operation as a descension.
- The game immediately ends when there are no two consecutive positive integers. Your task is to end the game so that the total cost of your operations is as small as possible.
Obviously, every game ends after at most n - 1 descensions. Please share your solution of this game with the lowest cost.
东也好,西也罢,家才是最好的归宿。正因如此,家庭团聚——农历新年庆祝活动中不可或缺的必要环节——才被置于如此重要的地位。
团圆饭后,小汤米和家人一起玩一个游戏。以下是该游戏的简明介绍:
- 游戏初始时有一个由 n 个非负整数 p1,p2,…,pn 构成的序列。规定该序列中任意时刻每个整数都必须为非负数。
- 你可以选择该序列中两个相邻的正整数 pi 和 pi+1(其中 1≤i<n),并将它们同时减去二者的最小值(即 min(pi,pi+1));该操作的代价等于 min(pi,pi+1)。我们将此类操作称为“递减操作”(descension)。
- 当序列中不再存在两个相邻的正整数时,游戏立即结束。你的任务是通过一系列操作使游戏结束,并使得所有操作的总代价尽可能小。
显然,每局游戏至多经过 n−1 次递减操作便会结束。请给出使总代价最小的游戏结束方案。
输入格式
The first line contains one integer n (1 ≤ n ≤ 3·105).
The second line contains n space-separated integers _p_1, _p_2, ..., p__n (0 ≤ p__i ≤ 109, i = 1, 2, ..., n).
第一行包含一个整数 n(1≤n≤3⋅105)。
第二行包含 n 个以空格分隔的整数 p1, p2, …, pn(0≤pi≤109,i=1, 2, …, n)。
输出格式
In the first line print one integer as the number of descensions m (0 ≤ m ≤ n - 1).
In the next m lines print the descensions chronologically. More precisely, in each line of the next m lines print one integer i (1 ≤ i < n) representing a descension would operate on p__i and p__i + 1 such that all the descensions could be utilized from top to bottom.
If there are many possible solutions to reach the minimal cost, print any of them.
第一行输出一个整数,表示下降操作的次数 m(0 ≤ m ≤ n − 1)。
接下来的 m 行按时间顺序输出各次下降操作。更准确地说,在接下来的 m 行中,每行输出一个整数 i(1 ≤ i < n),表示该次下降操作作用于 pi 和 pi+1,且所有下降操作可自上而下依次执行。
若存在多种方案均可达到最小代价,输出任意一种即可。
输入输出样例
输入#1
4 2 1 3 1
输出#1
2 1 3
输入#2
5 2 2 1 3 1
输出#2
3 2 1 4
说明/提示
In the first sample, one possible best solution is
, of which the cost is 1 + 1 = 2.
In the second sample, one possible best solution is
, of which the cost is 1 + 1 + 1 = 3.
在第一个样例中,一种可能的最优解是
,其代价为 1+1=2。
在第二个样例中,一种可能的最优解是
,其代价为 1+1+1=3。
输入解题思路,AI测评打分。不知道怎么写?