A8702 | Weather
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Scientists say a lot about the problems of global warming and cooling of the Earth. Indeed, such natural phenomena strongly influence all life on our planet.
Our hero Vasya is quite concerned about the problems. He decided to try a little experiment and observe how outside daily temperature changes. He hung out a thermometer on the balcony every morning and recorded the temperature. He had been measuring the temperature for the last $n$ days. Thus, he got a sequence of numbers $t_{1},t_{2},...,t_{n}$ , where the $i$ -th number is the temperature on the $i$ -th day.
Vasya analyzed the temperature statistics in other cities, and came to the conclusion that the city has no environmental problems, if first the temperature outside is negative for some non-zero number of days, and then the temperature is positive for some non-zero number of days. More formally, there must be a positive integer $k$ ( $1<=k<=n-1$ ) such that $t_{1}<0,t_{2}<0,...,t_{k}<0$ and $t_{k+1}>0,t_{k+2}>0,...,t_{n}>0$ . In particular, the temperature should never be zero. If this condition is not met, Vasya decides that his city has environmental problems, and gets upset.
You do not want to upset Vasya. Therefore, you want to select multiple values of temperature and modify them to satisfy Vasya's condition. You need to know what the least number of temperature values needs to be changed for that.
Our hero Vasya is quite concerned about the problems. He decided to try a little experiment and observe how outside daily temperature changes. He hung out a thermometer on the balcony every morning and recorded the temperature. He had been measuring the temperature for the last $n$ days. Thus, he got a sequence of numbers $t_{1},t_{2},...,t_{n}$ , where the $i$ -th number is the temperature on the $i$ -th day.
Vasya analyzed the temperature statistics in other cities, and came to the conclusion that the city has no environmental problems, if first the temperature outside is negative for some non-zero number of days, and then the temperature is positive for some non-zero number of days. More formally, there must be a positive integer $k$ ( $1<=k<=n-1$ ) such that $t_{1}<0,t_{2}<0,...,t_{k}<0$ and $t_{k+1}>0,t_{k+2}>0,...,t_{n}>0$ . In particular, the temperature should never be zero. If this condition is not met, Vasya decides that his city has environmental problems, and gets upset.
You do not want to upset Vasya. Therefore, you want to select multiple values of temperature and modify them to satisfy Vasya's condition. You need to know what the least number of temperature values needs to be changed for that.
输入格式
The first line contains a single integer $n$ ( $2<=n<=10^{5}$ ) — the number of days for which Vasya has been measuring the temperature.
The second line contains a sequence of $n$ integers $t_{1},t_{2},...,t_{n}$ $(|t_{i}|<=10^{9})$ — the sequence of temperature values. Numbers $t_{i}$ are separated by single spaces.
The second line contains a sequence of $n$ integers $t_{1},t_{2},...,t_{n}$ $(|t_{i}|<=10^{9})$ — the sequence of temperature values. Numbers $t_{i}$ are separated by single spaces.
输出格式
Print a single integer — the answer to the given task.
输入输出样例
输入 #1
4 -1 1 -2 1
输出 #1
1
输入 #2
5 0 -1 1 2 -5
输出 #2
2
Note to the first sample: there are two ways to change exactly one number so that the sequence met Vasya's condition. You can either replace the first number 1 by any negative number or replace the number -2 by any positive number.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted