A. Second Order Statistics

来源:互联网 发布:mac 梦幻西游手游网页 编辑:程序博客网 时间:2024/05/22 05:22
A. Second Order Statistics
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statistics of the given sequence. In other words it is the smallest element strictly greater than the minimum. Help Bob solve this problem.

Input

The first input line contains integer n (1?≤?n?≤?100) — amount of numbers in the sequence. The second line contains n space-separated integer numbers — elements of the sequence. These numbers don't exceed 100 in absolute value.

Output

If the given sequence has the second order statistics, output this order statistics, otherwise output NO.

Sample test(s)
input
4
1 2 2 -4
output
1
input
5
1 2 3 1 1
output
2

qw
/* ***********************************************
Author :
Created Time :2015/6/11 20:04:16
File Name :7.cpp
************************************************ */

#include <iostream>
#include <cstring>
#include <cstdlib>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <iomanip>
#include <list>
#include <deque>
#include <stack>
#define ull unsigned long long
#define ll long long
#define mod 90001
#define INF 1<<30
#define maxn 10000+10
#define cle(a) memset(a,0,sizeof(a))
const ull inf = 1LL << 61;
const double eps=1e-5;
using namespace std;

bool cmp(int a,int b){
return a>b;
}
int a[maxn];
map
<int,int>mp;
int main()
{
#ifndef ONLINE_JUDGE
//freopen("in.txt","r",stdin);
#endif
//freopen("out.txt","w",stdout);
int n;
while(cin>>n){
int cnt=0;
for(int i=0;i<n;i++){
cin
>>a[i];
if(mp[a[i]]==0){
mp
[a[i]]++;
cnt
++;
}
}
if(cnt<2)cout<<"NO"<<endl;
else {
sort
(a,a+n);
unique
(a,a+n);
cout
<<a[1]<<endl;
}
}
return 0;
}
#include <cmath>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>

#include <algorithm>
#include <vector>
#include <string>
#include <sstream>
#include <iostream>
#include <functional>
#include <map>
#include <set>

using namespace std;

#define forn(i, n) for (int i = 0; i < (int)(n); i++)
#define forit(i, a) for (__typeof((a).begin()) i = (a).begin(); i != (a).end(); i++)
#define sz(a) (int)(a).size()
#define all(a) (a).begin(), (a).end()
#define zero(a) memset(a, 0, sizeof(a))
#define pb push_back
#define mp make_pair

typedef long long ll;
typedef vector <int> vi;
typedef pair <int, int> pii;

const int maxn = (int)1e5 + 10;

int n, a[maxn];

int main()
{
scanf
("%d", &n);
forn
(i, n)
scanf
("%d", &a[i]);
sort
(a, a + n);
if (unique(a, a + n) - a < 2)
puts
("NO");
else
printf
("%d\n", a[1]);
return 0;
}

0 0
原创粉丝点击