#P8847. [JRKSJ R5] 1-1 A

    ID: 9232 远端评测题 1000ms 128MiB 尝试: 0 已通过: 0 难度: 3 上传者: 标签>2022洛谷原创Special Judge构造洛谷月赛

[JRKSJ R5] 1-1 A

Background

This problem is an easier version of 1-1. The harder version is 1-1 B.

Problem Description

You are given a sequence aa. For all i[1,n]i \in [1,n], ai{1,1}a_i \in \{1,-1\}.

You may reorder the sequence arbitrarily. You need to minimize the maximum subarray sum of the sequence after reordering.

Input Format

The first line contains an integer nn.

The second line contains nn integers representing aa.

Output Format

Output one line with nn integers separated by spaces, representing the reordered sequence.

If there are multiple solutions, output any one of them.

4
1 1 -1 -1
1 -1 -1 1

Hint

Definition of the maximum subarray sum: the maximum value of the sum over any subarray of the sequence, i.e. max1lrni=lrai\max_{1\le l\le r\le n} \sum_{i=l}^r a_i.

This problem uses Special Judge\text{Special Judge}. As long as your output satisfies the requirements, it will be accepted.

The input and output files of this problem are large, so please use appropriate input and output methods.

Constraints

This problem uses bundled testdata.

Subtask\text{Subtask} nn \le Score\text{Score}
11 1010 4040
22 10610^6 6060

For 100%100\% of the testdata, 1n1061 \le n \le 10^6, and ai{1,1}a_i \in \{1,-1\}.

Translated by ChatGPT 5