#include <cstdio>
#include <algorithm>
using namespace std;
int main(){
int n;
scanf("%d", &n);
int arr[n];
for(int i=0; i<n; i++){
scanf("%d", &arr[i]);
}
sort(arr, arr+n);
int temp, low=0, high=0;
if(n % 2 == 0){
temp = arr[n/2];
for(int i=0; i<n/2; i++){
if(arr[i] < temp){
low++;
}
}
for(int i=n/2+1; i<n; i++){
if(arr[i] > temp){
high++;
}
}
}else{
temp = arr[n/2];
for(int i=0; i<n/2; i++){
if(arr[i] < temp){
low++;
}
}
for(int i=n/2+1; i<n; i++){
if(arr[i] > temp){
high++;
}
}
}
if(high == low){
printf("%d", temp);
}else{
printf("-1");
}
}
CCF CSP-201612-1 中间数(C++)
最新推荐文章于 2021-03-04 00:15:50 发布