• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • YouClaw
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
HaibaraAi
博客园    首页    新随笔    联系   管理    订阅  订阅

Codechef TechFest 2013 Balancing nature

Balancing nature

Problem code: TCFST06

  • My Submissions
  • All Submissions
 

All submissions for this problem are available.

 

There are three kinds of possibilities about temperature in cities around the world, one whose temperature remains negative, second whose temperature remains positive, and the rest that have temperatures varying from negative to positive values.

Now, our very own poster boy Divyam, decides to do a quick analysis of the temperature of cities. For a city, he records temperatures t(1), t(2) … t(n) for n days where t(i) is the temperature on the i-th day. Divyam’s hypothesis is justified if first the temperature is negative for some non-zero number of days and then positive for non zero number of days.

In particular the temperature should never be zero. and there must be a positive integer k lying between 1 and (n-1) (both inclusive) for which the temperature values are all negative and from k+1 to n the temperature values are all positive.

Divyam becomes happy only if his hypothesis is satisfied, and your task is to keep him happy. Thus making you to modify some temperature values to fit the conditions of his hypothesis. Find the minimum number of such values that are required to be modified

 

Input

The first line contains a single integer n - representing the number of days for which Divyam runs his hypothesis testing experiment.
The second line contains n integers t(1), t(2), ..., t(n) — which is sequence of measured temperature values. Numbers ti are separated by single spaces.

 

Output

Print a single integer — the answer to the given task.

 

Constraints

2 ≤ n ≤ 105
|t(i)| ≤ 109

 

Example

Input:
5
0 -4 1 1 -3
Output:
2
 1 #pragma comment(linker, "/STACK:1024000000,1024000000")
 2 #include <map>
 3 #include <queue>
 4 #include <vector>
 5 #include <string>
 6 #include <cmath>
 7 #include <cstdio>
 8 #include <cstring>
 9 #include <cstdlib>
10 #include <iostream>
11 #include <algorithm>
12 using namespace std;
13 #define maxn 200005
14 #define ll long long
15 #define INF 0x7fffffff
16 #define eps 1e-8
17 int n, m;
18 vector<int>v1;
19 vector<int>v;
20 int main(){
21     int cas = 1;
22     int t;
23     while (~scanf("%d",&n)){
24         v.clear(); v1.clear();
25         int c0=0, c1=0, c2;
26         for (int i = 0; i < n; i++){
27             scanf("%d", &t);
28             if (t == 0)c0++;
29             if (t < 0)v1.push_back(i);
30             v.push_back(t);
31         }
32         int mi = INF;
33         for (int i = 0; i < n; i++){
34             if (v[i]>0)c1++;
35             c2 = v1.end() - lower_bound(v1.begin(), v1.end(), i + 1);
36             mi = min(mi, c1 + c2);
37         }
38         printf("%d\n", c0 + mi);
39     }
40     return 0;
41 }
View Code
posted @ 2013-10-29 14:43  HaibaraAi  阅读(102)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3