A8845 | Paper Work
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Polycarpus has been working in the analytic department of the "F.R.A.U.D." company for as much as $n$ days. Right now his task is to make a series of reports about the company's performance for the last $n$ days. We know that the main information in a day report is value $a_{i}$ , the company's profit on the $i$ -th day. If $a_{i}$ is negative, then the company suffered losses on the $i$ -th day.
Polycarpus should sort the daily reports into folders. Each folder should include data on the company's performance for several consecutive days. Of course, the information on each of the $n$ days should be exactly in one folder. Thus, Polycarpus puts information on the first few days in the first folder. The information on the several following days goes to the second folder, and so on.
It is known that the boss reads one daily report folder per day. If one folder has three or more reports for the days in which the company suffered losses $(a_{i}<0)$ , he loses his temper and his wrath is terrible.
Therefore, Polycarpus wants to prepare the folders so that none of them contains information on three or more days with the loss, and the number of folders is minimal.
Write a program that, given sequence $a_{i}$ , will print the minimum number of folders.
Polycarpus should sort the daily reports into folders. Each folder should include data on the company's performance for several consecutive days. Of course, the information on each of the $n$ days should be exactly in one folder. Thus, Polycarpus puts information on the first few days in the first folder. The information on the several following days goes to the second folder, and so on.
It is known that the boss reads one daily report folder per day. If one folder has three or more reports for the days in which the company suffered losses $(a_{i}<0)$ , he loses his temper and his wrath is terrible.
Therefore, Polycarpus wants to prepare the folders so that none of them contains information on three or more days with the loss, and the number of folders is minimal.
Write a program that, given sequence $a_{i}$ , will print the minimum number of folders.
输入格式
The first line contains integer $n$ ( $1<=n<=100$ ), $n$ is the number of days. The second line contains a sequence of integers $a_{1},a_{2},...,a_{n}$ ( $|a_{i}|<=100$ ), where $a_{i}$ means the company profit on the $i$ -th day. It is possible that the company has no days with the negative $a_{i}$ .
输出格式
Print an integer $k$ — the required minimum number of folders. In the second line print a sequence of integers $b_{1}$ , $b_{2}$ , ..., $b_{k}$ , where $b_{j}$ is the number of day reports in the $j$ -th folder.
If there are multiple ways to sort the reports into $k$ days, print any of them.
If there are multiple ways to sort the reports into $k$ days, print any of them.
输入输出样例
输入 #1
11 1 2 3 -4 -5 -6 5 -5 -6 -7 6
输出 #1
3 5 3 3
输入 #2
5 0 -1 100 -1 0
输出 #2
1 5
Here goes a way to sort the reports from the first sample into three folders:
1 2 3 -4 -5 | -6 5 -5 | -6 -7 6In the second sample you can put all five reports in one folder.
1 2 3 -4 -5 | -6 5 -5 | -6 -7 6In the second sample you can put all five reports in one folder.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted