CF234C.Weather

普及-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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.

科学家们经常谈论全球变暖和地球降温等问题。事实上,这类自然现象对地球上所有生命都有强烈影响。

我们的主人公瓦夏非常关注这些问题。他决定进行一个小实验,观察室外日温度的变化情况。他每天早晨都在阳台上挂一支温度计并记录温度。他已连续测量了最近 nn 天的温度,因此得到了一个数列 t1, t2, …, tnt_1,\,t_2,\,\dots,\,t_n,其中第 ii 个数表示第 ii 天的温度。

瓦夏分析了其他城市的气温统计数据,并得出结论:若某城市先经历若干天(天数为非零正整数)的负温,再经历若干天(天数也为非零正整数)的正温,则该城市没有环境问题。更准确地说,必须存在一个正整数 kk(满足 1≤k≤n−11\leq k\leq n-1),使得

t1<0,  t2<0,  …,  tk<0且tk+1>0,  tk+2>0,  …,  tn>0.t_1 < 0,\; t_2 < 0,\; \dots,\; t_k < 0 \quad \text{且} \quad t_{k+1} > 0,\; t_{k+2} > 0,\; \dots,\; t_n > 0.

特别地,温度绝不能为零。若不满足此条件,瓦夏便认为自己的城市存在环境问题,并感到沮丧。

你不想让瓦夏沮丧。因此,你希望选择若干温度值并修改它们,使其满足瓦夏的条件。你需要求出:最少需要修改多少个温度值?

输入格式

The first line contains a single integer n (2 ≤ n ≤ 105) — 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| ≤ 109) — the sequence of temperature values. Numbers t__i are separated by single spaces.

第一行包含一个整数 nn(2≤n≤1052 \leq n \leq 10^5)—— 表示瓦夏测量温度的天数。

第二行包含一个由 nn 个整数 t1, t2, …, tnt_1,\ t_2,\ \dots,\ t_n(∣ti∣≤109|t_i| \leq 10^9)组成的序列 —— 表示温度值序列。数字 tit_i 以单个空格分隔。

输出格式

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.

第一个样例的说明:恰好修改一个数使得序列满足瓦西亚条件的方法有两种。你可以将第一个数 11 替换为任意负数,或者将数 −2-2 替换为任意正数。

输入解题思路,AI测评打分。不知道怎么写?

首页