BOJ 6986 절사평균

 
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <functional>

typedef long long int ll;
using namespace std;
#define INF 1234567890
#define N 200000

const int LIMIT = 1e+9;
int n, m;
double values[100005];

ll powf(ll base, ll exp) {
	ll res = 1;
	while (exp) {
		if (exp & 1)
			res *= base;
		exp >>= 1;
		base *= base;
	}
	return res;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	cin >> n >> m;

	for (int i = 0; i < n; i++) {
		cin >> values[i];
	}
	sort(values, values + n);
	double sum = 0;
	for (int i = m; i < n - m; i++) {
		sum += values[i];
	}
	cout << fixed;
	cout.precision(2);
	cout << sum / (n - m*2) + 1e-9 << "\n";
	sum += values[m] * m;
	sum += values[n - m - 1] * m;
	cout << sum / n + 1e-9;

	return 0;
}