A. Be Positive

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

You are given an array of nn integers: a1,a2,…,ana1,a2,…,an. Your task is to find some non-zero integer dd (−103≤d≤103−103≤d≤103) such that, after each number in the array is divided by dd, the number of positive numbers that are presented in the array is greater than or equal to half of the array size (i.e., at least ⌈n2⌉⌈n2⌉). Note that those positive numbers do not need to be an integer (e.g., a 2.52.5 counts as a positive number). If there are multiple values of dd that satisfy the condition, you may print any of them. In case that there is no such dd, print a single integer 00.

Recall that ⌈x⌉⌈x⌉ represents the smallest integer that is not less than xx and that zero (00) is neither positive nor negative.

Input

The first line contains one integer nn (1≤n≤1001≤n≤100) — the number of elements in the array.

The second line contains nn space-separated integers a1,a2,…,ana1,a2,…,an (−103≤ai≤103−103≤ai≤103).

Output

Print one integer dd (−103≤d≤103−103≤d≤103 and d≠0d≠0) that satisfies the given condition. If there are multiple values of dd that satisfy the condition, you may print any of them. In case that there is no such dd, print a single integer 00.

Examples

input

5
10 0 -7 2 6

output

4

input

7
0 0 1 -1 0 0 2

output

0

Note

In the first sample, n=5n=5, so we need at least ⌈52⌉=3⌈52⌉=3 positive numbers after division. If d=4d=4, the array after division is [2.5,0,−1.75,0.5,1.5][2.5,0,−1.75,0.5,1.5], in which there are 33 positive numbers (namely: 2.52.5, 0.50.5, and 1.51.5).

In the second sample, there is no valid dd, so 00 should be printed.

题解:计算出正数和负数的个数,如果正数大于(n+1)/2的话,就是随便输出一个正数,如果负数大于(n+1)/2的话,就随便输出一个负数,否则输出0.

#include<iostream>
#include<cstdio> using namespace std; int main()
{
int n,a[],cnt=,cnt2=;
cin>>n;
for(int i=;i<n;i++)
{
scanf("%d",a+i);
if(a[i]>) //找出正数的个数
cnt++;
else if(a[i]<) //找出负数的个数
cnt2++; }
if(cnt>=(n+)/)
printf("1\n");
else if(cnt2>=(n+)/)
printf("-1\n");
else
printf("0\n");
return ;
}

A. Be Positive的更多相关文章

  1. [LeetCode] First Missing Positive 首个缺失的正数

    Given an unsorted integer array, find the first missing positive integer. For example,Given [1,2,0]  ...

  2. Leetcode First Missing Positive

    Given an unsorted integer array, find the first missing positive integer. For example,Given [1,2,0]  ...

  3. Interleaving Positive and Negative Numbers

    Given an array with positive and negative integers. Re-range it to interleaving with positive and ne ...

  4. 【leetcode】First Missing Positive

    First Missing Positive Given an unsorted integer array, find the first missing positive integer. For ...

  5. 【leetcode】First Missing Positive(hard) ☆

    Given an unsorted integer array, find the first missing positive integer. For example,Given [1,2,0]  ...

  6. LeetCode - 41. First Missing Positive

    41. First Missing Positive Problem's Link ---------------------------------------------------------- ...

  7. LeetCode题解-----First Missing Positive

    Given an unsorted integer array, find the first missing positive integer. For example,Given [1,2,0]  ...

  8. hdu 5183. Negative and Positive (哈希表)

    Negative and Positive (NP) Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 65536/65536 K (Ja ...

  9. Java for LeetCode 041 First Missing Positive

    Given an unsorted integer array, find the first missing positive integer. For example, Given [1,2,0] ...

  10. [LintCode] Interleaving Positive and Negative Numbers

    Given an array with positive and negative integers. Re-range it to interleaving with positive and ne ...

随机推荐

  1. LZH的多重影分身 qduoj 思维 差分

    LZH的多重影分身 qduoj 思维 差分 原题链接:https://qduoj.com/problem/591 题意 在数轴上有\(n\)个点(可以重合)和\(m\)条线段(可以重叠),你可以同时平 ...

  2. # ACM奇淫技巧

    目录 ACM奇淫技巧 差分操作 坐标旋转 ACM 卡常优化 vsc代码块(头文件模板) 读入输出优化 逗号表达式 内联函数inline 寄存器变量register 条件判断加减代替取模 自增运算符优化 ...

  3. Mysql学习(三)之数据库管理工具Navicat

    前言 mysql安装完后默认只有命令行工具,所以我们可以下载一些数据库管理工具Navicat Navicat使用 首先建立一个连接选择mysql,填写信息 发现多了一个localhost,双击,打开连 ...

  4. react 不同环境配置不同域名

    npm eject 先将配置文件暴露出来 将scripts中的build文件复制一份,改名为你需要的名字 将其中的 process.env.NODE_ENV 赋值为你需要的环境 在package.js ...

  5. 一头扎进 JAVA

    硅不可 吉米 JAVA 基础 -- 基础不牢,地动山摇 子类应该比 父类更为 开放 (public protected default private) 子类方法不能比父类抛出更高异常( 可以为父类方 ...

  6. BLOB和CLOB

    mysql各数据类型及字节长度一览表: 数据类型 字节长度 范围或用法 Bit 1 无符号[0,255],有符号[-128,127],天缘博客备注:BIT和BOOL布尔型都占用1字节 TinyInt ...

  7. 关于页面多个ajax请求阻塞的问题

    最近遇到一个问题,我的一个页面有多个ajax请求,但是一个很快的请求却需要很长时间才返回,而且慢于一个耗时比较长的请求,我在考虑是不是有ajax异步并发有问题,但是查询了一些资料,ajax不存在这样的 ...

  8. 5.(基础)tornado异步

    终于到了传说中的异步了,感觉异步这个名字听起来就很酷酷的,以前还不是多擅长Python时,就跑去看twisted的源码,结果给我幼小的心灵留下了创伤.反正包括我在内,都知道异步编程很强大,但是却很少在 ...

  9. enum:python实现枚举也很优雅

    介绍 enum是一个用来枚举的模块 创建枚举类型 import enum # 创建一个类,继承自enum下的Enum class Color(enum.Enum): red = 1 green = 2 ...

  10. Chrome OS 更新新版本可让Linux访问USB连接的Android设备

    谷歌再次为Chrome OS带来了重大版本更新,使版本号达到了75.本次更新的一大亮点就是允许在Chrome OS上运行的Linux能够识别通过USB方式连接的Android设备,能够让用户使用Lin ...