Nathan Coulas

DMOPC '14 Contest 1 P1 - Median Mark

dmopc14c1p1 CPP17 04 May, 2020 0.123s 5 points

Source Code

#include <bits/stdc++.h>
using namespace std;


int main() {
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	int n;
	cin >> n; 
	int arr[n];
	
	for(int i = 0; i < n; i++){
		cin >> arr[i]; 
	}
	
	sort(arr, arr + n);
	
	if(n % 2 == 0){
		cout << (int)round(1.0 * (arr[n / 2] + arr[n / 2 - 1]) / 2);
	}else{
		cout << arr[n / 2];
	}
	
	return 0;
  }