CF300A.Array

普及-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Vitaly has an array of n distinct integers. Vitaly wants to divide this array into three non-empty sets so as the following conditions hold:

  1. The product of all numbers in the first set is less than zero ( < 0).
  2. The product of all numbers in the second set is greater than zero ( > 0).
  3. The product of all numbers in the third set is equal to zero.
  4. Each number from the initial array must occur in exactly one set.

Help Vitaly. Divide the given array.

维塔利有一个包含 nn 个互不相同整数的数组。他希望将该数组划分为三个非空集合,使得满足以下条件:

  1. 第一个集合中所有数的乘积小于零(<0< 0);
  2. 第二个集合中所有数的乘积大于零(>0> 0);
  3. 第三个集合中所有数的乘积等于零(=0= 0);
  4. 初始数组中的每个数恰好出现在其中一个集合中。

请帮助维塔利完成这一划分。

输入格式

The first line of the input contains integer n (3 ≤ n ≤ 100). The second line contains n space-separated distinct integers _a_1, _a_2, ..., a__n (|a__i| ≤ 103) — the array elements.

输入的第一行包含一个整数 nn(3≤n≤1003 \leq n \leq 100)。第二行包含 nn 个由空格分隔的互不相同的整数 a1, a2, …, ana_1,\ a_2,\ \dots,\ a_n(∣ai∣≤103|a_i| \leq 10^3)——即数组元素。

输出格式

In the first line print integer _n_1 (_n_1 > 0) — the number of elements in the first set. Then print _n_1 numbers — the elements that got to the first set.

In the next line print integer _n_2 (_n_2 > 0) — the number of elements in the second set. Then print _n_2 numbers — the elements that got to the second set.

In the next line print integer _n_3 (_n_3 > 0) — the number of elements in the third set. Then print _n_3 numbers — the elements that got to the third set.

The printed sets must meet the described conditions. It is guaranteed that the solution exists. If there are several solutions, you are allowed to print any of them.

第一行输出整数 n1n_1(n1>0n_1 > 0)—— 第一个集合中的元素个数。然后输出 n1n_1 个数——进入第一个集合的元素。

下一行输出整数 n2n_2(n2>0n_2 > 0)—— 第二个集合中的元素个数。然后输出 n2n_2 个数——进入第二个集合的元素。

下一行输出整数 n3n_3(n3>0n_3 > 0)—— 第三个集合中的元素个数。然后输出 n3n_3 个数——进入第三个集合的元素。

所输出的集合必须满足题目描述的条件。保证解存在。若存在多个解,输出任意一个即可。

输入输出样例

  • 输入#1

    3
    -1 2 0

    输出#1

    1 -1
    1 2
    1 0
  • 输入#2

    4
    -1 -2 -3 0

    输出#2

    1 -1
    2 -3 -2
    1 0

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

首页