1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <iostream>

int marks[1000000];

int main(int argc, char** argv) {
	std::ios::sync_with_stdio(false);
	int n;
	unsigned long long sum = 0;
	std::cin >> n;
	for (int i = 0; i < n; i++) {
		std::cin >> marks[i];
		sum += marks[i];
	}
	int l = 0;
	int r = n - 1;
	float target = 2 * n + 1;
	int parmutations = 0;
	float median = sum / n;
	float epsilion = 0.00001f;
	if (median * 2 + 1 == target)
		parmutations++;
	
	while (l < r) {
		if (marks[l] < marks[r]) {
			sum -= marks[l];
			n--;
			median = static_cast<float>(sum) / n;
			if (abs(target - median * 2 - n) <= epsilion)
				parmutations++;
			l++;
		}
		else {
			sum -= marks[r];
			n--;
			median = static_cast<float>(sum) / n;
			if (abs(target - median * 2 - n) <= epsilion)
				parmutations++;
			r--;
		}
	}
	std::cout << target << " " << parmutations;
}