Codeforces 768A Oath of the Night's Watch

简介: A. Oath of the Night's Watch time limit per test:2 seconds memory limit per test:256 megabytes input:standard input outp...
A. Oath of the Night's Watch
time limit per test:2 seconds
memory limit per test:256 megabytes
input:standard input
output:standard output

"Night gathers, and now my watch begins. It shall not end until my death. I shall take no wife, hold no lands, father no children. I shall wear no crowns and win no glory. I shall live and die at my post. I am the sword in the darkness. I am the watcher on the walls. I am the shield that guards the realms of men. I pledge my life and honor to the Night's Watch, for this night and all the nights to come." — The Night's Watch oath.

With that begins the watch of Jon Snow. He is assigned the task to support the stewards.

This time he has n stewards with him whom he has to provide support. Each steward has his own strength. Jon Snow likes to support a steward only if there exists at least one steward who has strength strictly less than him and at least one steward who has strength strictly greater than him.

Can you find how many stewards will Jon support?

Input

First line consists of a single integer n (1 ≤ n ≤ 105) — the number of stewards with Jon Snow.

Second line consists of n space separated integers a1, a2, ..., an (0 ≤ ai ≤ 109) representing the values assigned to the stewards.

Output

Output a single integer representing the number of stewards which Jon will feed.

Examples
Input
2

1 5
Output
0
Input
3

1 2 5
Output
1
Note

In the first sample, Jon Snow cannot support steward with strength 1 because there is no steward with strength less than 1 and he cannot support steward with strength 5 because there is no steward with strength greater than 5.

In the second sample, Jon Snow can support steward with strength 2 because there are stewards with strength less than 2 and greater than 2.

 题目链接:http://codeforces.com/problemset/problem/768/A

分析:把数字排下序,取最大值和最小值,然后分别进行比较,用一个数去计算其个数即可!

下面给出AC代码:

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 int main()
 4 {
 5     int n;
 6     int a[100005];
 7     while(scanf("%d",&n)!=EOF)
 8     {
 9         int ans=0;
10         for(int i=1;i<=n;i++)
11             scanf("%d",&a[i]);
12             sort(a+1,a+1+n);
13         if(n==1||n==2)
14             printf("0\n");
15         if(n>=3)
16         {
17             int minn=a[1];
18             int maxn=a[n];
19             for(int i=2;i<=n-1;i++)
20                 if(a[i]>minn&&a[i]<maxn)
21                     ans++;
22                     printf("%d\n",ans);
23         }
24     }
25     return 0;
26 }

 

目录
相关文章
|
12月前
Codeforces Round #192 (Div. 2) (330B) B.Road Construction
要将N个城市全部相连,刚开始以为是最小生成树的问题,其实就是一道简单的题目。 要求两个城市之间不超过两条道路,那么所有的城市应该是连在一个点上的,至于这个点就很好找了,只要找到一个没有和其他点有道路限制的即可。
36 0
|
机器学习/深度学习 人工智能
Educational Codeforces Round 113 (Rated for Div. 2)C. Jury Meeting
Educational Codeforces Round 113 (Rated for Div. 2)C. Jury Meeting
51 0
|
人工智能 Windows
Educational Codeforces Round 113 (Rated for Div. 2) C - Jury Meeting (思维 组合数)
Educational Codeforces Round 113 (Rated for Div. 2) C - Jury Meeting (思维 组合数)
93 0
|
机器学习/深度学习 Java
codeforces Educational Codeforces Round 49 (Rated for Div. 2) C题
刚开始拿到这题很懵逼,知道了别人的思路之后开始写,但是还是遇到很多坑,要求求P2/S最大。p=a b。就是求(a2+ b2 +2ab)/ab最大,也就是a/b +b/a最大。那么题意就很明显了。
112 0