#P10811. 【MX-S2-T2】 排
【MX-S2-T2】 排
Background
Original problem link: https://oier.team/problems/S2B.
Problem Description
There are integers . Let , and $f_i= \left\{ \begin{aligned} & f_{i-1} & \ f_{i-1}\times a_i>0, \\ & f_{i-1}+a_i & \ f_{i-1}\times a_i\le 0.\\ \end{aligned} \right.$ Reorder so that the resulting is maximized.
Input Format
The first line contains one integer .
The second line contains integers .
Output Format
Output one integer in one line, representing the answer.
5
7 5 -4 -6 3
6
10
573 -1339 899 939 -26 1430 1324 -1150 1640 -45
1625
Hint
[Sample Explanation #1]
Consider reordering as . The final is . It can be proven that there is no better arrangement.
[Constraints]
This problem uses bundled testdata.
- Subtask 0 (6 pts): .
- Subtask 1 (14 pts): , .
- Subtask 2 (8 pts): all numbers in are positive, or all are negative.
- Subtask 3 (19 pts): there is exactly one positive number in (note that may contain ).
- Subtask 4 (29 pts): , .
- Subtask 5 (24 pts): no special constraints.
For all testdata, , .
Translated by ChatGPT 5