#P7652. [BalticOI 1996] A NICE SEQUENCE (Day 1)
[BalticOI 1996] A NICE SEQUENCE (Day 1)
Description
There is a sequence consisting of integers. A sequence is a subsequence of the given sequence if:
- For each (), there exists a () such that ;
- For any and with , if and , then the relation holds.
The sequence is non-increasing if for every (), .
The sequence is non-decreasing if for every (), .
The given sequence is called NICE if we can choose subsequences of this sequence such that:
- Each subsequence has at least elements;
- Each subsequence is either non-increasing or non-decreasing;
- Every element of the given sequence belongs to exactly one subsequence.
Find the minimum possible for the given sequence.
Input Format
The first line contains an integer . The next lines contain the elements of the sequence (one integer per line, and for each , ).
Output Format
The output must contain:
- The value of in the first line;
- One example of a partition of the given sequence into subsequences (that is, there must be lines, each containing and the index ( index ) of the subsequence to which belongs).
If the given sequence is not NICE, then the first line of the output must contain only .
6
12
33
97
18
15
33
2
12 1
33 1
97 2
18 2
15 2
33 1
1
88
0
4
77
22
22
11
1
77 1
22 1
22 1
11 1
Hint
Constraints
For of the testdata, , .
Sample Explanation
In sample 1, the subsequences are and .
Scoring
The score of this problem follows the original BOI settings, with a full score of .
Notes
This problem comes from Day 1: A NICE SEQUENCE in Baltic Olympiad in Informatics 1996.
Translated and整理 (zhěng lǐ: organized) by @求学的企鹅.
Translated by ChatGPT 5
京公网安备 11011102002149号