RiseOJ는 solved.ac와 제휴 관계가 없습니다. 티어 아이콘 © solved.ac. solved.ac
포럼
문제 COCI00707

Rastući

스페셜 저지 — 출력을 사용자 정의 프로그램으로 검사하므로 여러 정답이 인정될 수 있습니다.
설명

The European Union recently passed a new law stating that all sequences must be
increasing, and starting from January 1, 2026, anyone possessing a sequence that
is not increasing will be strictly penalized. More precisely, a sequence \(a_{1}\), \(a_{2}\), ..., \(a_{n}\)
is illegal if there exists \(i\) (\(1 \le i < n\)) such that \(a_{i} > a_{i+1}\), and otherwise the
sequence is legal.
Ivica recently received a sequence as a gift and is worried that he might get into
trouble because of the new law. Fortunately, Ivica realized that he can take any
two adjacent elements of his sequence and replace them with their sum. More
precisely, if Ivica’s sequence is currently \(a_{1}\), \(a_{2}\), ..., \(a_{m}\), he can choose some \(k\) such
that \(1 \le k < m\) and replace his sequence with \(a_{1}\), \(a_{2}\), ..., a_{\(k - 1\)}, (\(a_{k} + a_{k+1}\)), a_{\(k+2\)}, ..., \(a_{m}\). Ivica can perform
this operation as many times as he wants, and his goal is to obtain a legal sequence using such operations.
Of course, Ivica does not want to completely destroy his sequence, so he would like to obtain the longest
possible legal sequence from his initial sequence. Help Ivica determine the length of the longest legal
sequence he can get from the initial sequence and output any such legal sequence of maximum length.

제약
입력 형식

In the first line, there is a natural number \(n\) (\(1 \le n \le 5000\)), the length of Ivica’s sequence.
In the second line, there are \(n\) natural numbers \(a_{i}\) (\(1 \le a_{i} \le 10^{9}\)), the sequence that Ivica received as a
gift.

출력 형식

In the first line, print a single number m - the length of the longest valid sequence that Ivica can obtain
from the initial sequence.
In the second line, print \(m\) numbers, the elements of one of the valid sequences of length \(m\) that Ivica can
obtain from the initial sequence. If there are multiple such sequences, print any one of them.

서브태스크
서브태스크점수설명

1

10점

\(n \le 20\)

2

15점

\(n \le 100\), \(a_{i} \le 100\)

3

20점

\(n \le 500\)

4

25점

\(n \le 1000\)

5

40점

No additional constraints. 60% of the points for a test case are earned by having a correct output of the 1st line. The remaining 40% of the points for the test case are earned by having a correct output of the 2nd line.

예제 1
입력
6
3 2 6 3 3 8
출력
4
5 6 6 8
예제 2
입력
7
3 6 4 2 6 2 5
출력
5
3 6 6 6 7
설명

Clarification of the first example: In the first operation, Ivica will replace the first 2 elements of the
array with their sum and obtain the illegal array [5, 6, 3, 3, 8]. Then, he will replace the third and fourth
elements of the array with their sum and obtain the legal array [5, 6, 6, 8]. It can be shown that this is a
legal array of maximal length that can be obtained from the initial array.

문제 정보

생성자가 기록되지 않았습니다.

출처 COCI 2025/2026 Contest 2

평가 및 의견

Rastući

개요
출제자 난이도 Unrated 레이팅 미적용 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

Rastući

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8