Solution for DMOPC '14 Contest 1 P1 - Median Mark in C++


May 4, 2020 0.122555 seconds C++
#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;
  }

Editorial


No editorial for this problem. :(

Original Problem


You can view the original page for this problem on the DMOJ.