logo AlgoBeat OnlineJudge
登录 注册

#206217. [NWRRC 2014] Fragmentation

内存限制:256 MiB 时间限制:2000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

Felix is working on a startup project in his garage. He has already found a great name for his project: SuperFastZilla. By now he is not sure what SuperFastZilla should do, but he is pretty sure it should do it fast, super fast.

Once he noticed that SuperFastZilla is working too slow, inspite of the fast algorithms used in it. Felix thinks that the problem may be caused by storage fragmentation.

The storage used by SuperFastZilla consists of blocks of memory. SuperFastZilla performs some operations on this storage. Each block is used in one operation only, the i-th block is used in the -th operation.

Felix wants to sort these blocks by the index of the operation they are used. To make it faster, Felix wants to split the storage into minimal number of segments of consecutive blocks, and then rearrange these segments to get the sorted array of blocks. After this rearrangement the order of block's indices of operations must be non-decreasing.

Help Felix to find the way to split the storage that minimizes the number of segments.

For example, if it can be split into three parts: and These parts can be rearranged to make the sorted array:

输入格式

The first line of input file contains an integer The next line contains integers

输出格式

The first line of the output file must contain an integer number — the minimal number of segments.

The next line must contains integers, the lengths of the segments, from left to right.

样例

样例输入 1

7
2 3 1 1 2 2 1

样例输出 1

3
2 4 1

数据范围与提示

Time limit: 2 s, Memory limit: 256 MB.