CF2229C1.We Be Flipping (Easy Version)

入门

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

This is the easy version of the problem. The difference between the versions is that in this version, you must minimise the sum. You can hack only if you solved all versions of this problem.

You have an array aa of length nn which consists of non-zero (but possibly negative) integers. You will perform the following operation at most nn times (possibly none):

  • select an index ii (1≤i≤n1 \le i \le n) such that ai>0a_i \gt 0
  • then for each jj where 1≤j≤i1 \le j \le i do aj:=−aja_j := -a_j.

Output a valid sequence of operations of length at most nn which minimises\color{red}{\text{minimises}} the sum of aa at the end.

这是该问题的简单版本。两个版本的区别在于:在本版本中,你必须最小化最终数组的元素和。仅当你解决了该问题的所有版本时,才可以进行 hack。

你有一个长度为 nn 的数组 aa,其中每个元素均为非零整数(但可能为负数)。你最多可以执行以下操作 nn 次(也可以不执行):

  • 选择一个下标 ii(满足 1≤i≤n1 \le i \le n),使得 ai>0a_i > 0;
  • 然后对每个满足 1≤j≤i1 \le j \le i 的 jj,执行 aj:=−aja_j := -a_j。

请输出一个长度至多为 nn 的合法操作序列,使得最终数组 aa 的元素和被最小化。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1041 \le t \le 10^4). The description of the test cases follows.

The first line of each testcase contains an integer nn (2≤n≤2⋅1052 \le n \le 2 \cdot 10^5) — the length of the array aa.

The second line of each testcase contains nn integers a1,a2,…,ana_1,a_2,\ldots,a_n (−109≤ai≤109,ai≠0-10^9 \le a_i \le 10^9, a_i \ne 0).

It is guaranteed that the sum of nn over all test cases does not exceed 2⋅1052 \cdot 10^5.

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤1041 \le t \le 10^4)。随后是各测试用例的描述。

每个测试用例的第一行包含一个整数 nn(2≤n≤2⋅1052 \le n \le 2 \cdot 10^5)—— 数组 aa 的长度。

每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1,a_2,\ldots,a_n(−109≤ai≤109-10^9 \le a_i \le 10^9,且 ai≠0a_i \ne 0)。

保证所有测试用例的 nn 之和不超过 2⋅1052 \cdot 10^5。

输出格式

For each testcase, output a single integer kk (0≤k≤n0 \le k \le n) — the number of operations you will perform.

Now output kk integers b1,…,bkb_1,\ldots,b_k where bib_i is the index you perform the iith operation on.

After performing the operations, the sum of aa should be minimal.

对于每个测试用例,输出一个整数 kk(0≤k≤n0 \le k \le n)—— 表示你将执行的操作次数。

接下来输出 kk 个整数 b1,…,bkb_1,\ldots,b_k,其中 bib_i 表示第 ii 次操作所作用的下标。

执行这些操作后,数组 aa 的元素之和应达到最小。

输入输出样例

  • 输入#1

    3
    5
    -1 -2 -3 -5 -4
    5
    -1 -2 3 -5 4
    4
    5 7 10 19

    输出#1

    0
    
    4
    3 5 4 2
    1
    4

说明/提示

In the first testcase, the sum is already minimised. So no operations are required.

In the second testcase, the operations are made as follows:

  • [−1,−2,3,−5,4]→i=3[1,2,−3,−5,4][-1, -2, 3, -5, 4] \xrightarrow{i = 3} [\color{red}{1, 2, -3}, -5, 4]
  • [1,2,−3,−5,4]→i=5[−1,−2,3,5,−4][1, 2, -3, -5, 4] \xrightarrow{i = 5} [\color{red}{-1, -2, 3, 5, -4}]
  • [−1,−2,3,5,−4]→i=4[1,2,−3,−5,−4][-1, -2, 3, 5, -4] \xrightarrow{i = 4} [\color{red}{1, 2, -3, -5}, -4]
  • [1,2,−3,−5,−4]→i=2[−1,−2,−3,−5,−4][1, 2, -3, -5, -4] \xrightarrow{i = 2} [\color{red}{-1, -2}, -3, -5, -4]

This has a sum of −15-15, which is the minimum possible.

在第一个测试用例中,和已经是最小值,因此无需执行任何操作。

在第二个测试用例中,操作过程如下:

  • [−1,−2,3,−5,4]→i=3[1,2,−3,−5,4][-1, -2, 3, -5, 4] \xrightarrow{i = 3} [\color{red}{1, 2, -3}, -5, 4]
  • [1,2,−3,−5,4]→i=5[−1,−2,3,5,−4][1, 2, -3, -5, 4] \xrightarrow{i = 5} [\color{red}{-1, -2, 3, 5, -4}]
  • [−1,−2,3,5,−4]→i=4[1,2,−3,−5,−4][-1, -2, 3, 5, -4] \xrightarrow{i = 4} [\color{red}{1, 2, -3, -5}, -4]
  • [1,2,−3,−5,−4]→i=2[−1,−2,−3,−5,−4][1, 2, -3, -5, -4] \xrightarrow{i = 2} [\color{red}{-1, -2}, -3, -5, -4]

最终数组的和为 −15-15,这是可能达到的最小值。

输入解题思路,AI测评打分。不知道怎么写?

首页