Drvca
의견: 0
Advent \(in\) Zagreb is a traditional holiday manifestation whose main attraction
is a magical Christmas market located at the city centre. It should also
be noted that this event was voted the best in Europe for three years in a
row. Apart from travelling fast, good news also has the tendency to travel
far. Indeed, the information about Advent in Zagreb reached North Pole
and Santa Claus himself. Interestingly enough, Santa never visited Croatia
(except for usual business on Christmas Eve). When you think about it, that
makes sense since he doesn’t really like summer activities by the sea and he
can solve COCI problems from the comfort of his own home.
Luckily, he decided to visit our Christmas market so he sent a letter to the town hall stating that he will
land on Zagreb’s main square in the early morning of December \(14^{th}\). After his \(on-si\)te participation in a
COCI round, he will have a guided tour of Zagreb’s finest gastronomic sites by Mr. Malnar.
You are probably wondering: “How exactly does Santa plan to land, there is no runway there!”. You are
right, there is not, but we’ll manage. The town hall already prepared \(N\) Christmas trees that should be
featured on the main square. Now, they will simply take those trees and place them in two rows which
will define the boundaries of the runway. For some reason they want to make the absolute difference in
height between each two neighbouring trees to be the same in each row. Moreover, they want to have the
trees sorted in each row from the shortest to the highest. Help them divide the trees into two rows that
satisfy these conditions.
Subtask
Score
Constraints
1
20
\(N \le 15\)
2
30
\(N \le 300\)
3
30
\(N \le 10^{5}\), there is a solution in which both rows have the same number of trees.
4
30
No additional constraints.
The first line contains an integer \(N\) (\(2 \le N \le 10^{5}\)) from the task description.
The next line contains \(N\) integers \(h@@RISE_MATH_BLOCK_0@@i \le 10^{9}\)) that denote the heights of all \(N\) Christmas trees.
In the first line you should output an integer \(A\) which represents the number of trees in the first row. In
the second line you should output \(A\) integers which represent the heights of the trees in the first row of
the runway.
In the third line you should output an integer \(B\) which represents the number of trees in the second row.
In the fourth line you should output \(B\) integers which represent the heights of the trees in the second row
of the runway.
The rows are not allowed to be empty (\(A > 0\) and \(B > 0\)) and each tree should be a part of one row
(\(A + B = N\)). Also, trees should be sorted in each row from the shortest to the highest. If there are
multiple solutions, you can output any of them. If there is no solution which satisfies the necessary
conditions, you should outp\(ut - 1\) in the only line of output.
4
1 3 2 42
1 2
2
3 46
23 4 7 6 8 153
4 6 8
3
7 15 236
1 2 3 7 9 10-1평가 및 의견
Drvca
Log in to rate problems.
아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.
풀이 제출
Drvca