题解 AT4290 【[ABC132C] Divide the Problems】
Zirnc
2020-02-23 11:25:23
[ChungZH's blog](https://chungzh.cn) · [ChungZH's portfolio](https://chungzh.cc)
> 高桥在竞争性编程中提出了 $N$ 个问题,问题编号为 $1$ 至 $N$,问题 $i$ 的难度表示为整数 $d_i$(越高难度越大)。
> 他通过选择整数 $K$ 将问题分为两类,如下所示:
> - 对于 _ARC_,难度为 K 或更高的问题。
> - 难度低于 K 的问题将是 _ABC_。
> 整数 $K$ 有多少种选择可以使 $ARC$ 的问题数和 $ABC$ 的问题数相同?
$k$ 的范围可以是整个数组中最接近平均数的两个数的差,比平均数小的都是 _ABC_,其他都是 _ARC_。
我们把 $d$ 数组排序,然后求中间两个数之间的差即可。
```cpp
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int n;
int a[100005];
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf("%d", &a[i]);
sort(a, a + n);
printf("%d\n", a[n / 2] - a[n / 2 - 1]);
return 0;
}
```