每日一题:Medians and Partition

题意

最多可以把数组分成几个部分,使得每部分中位数都大于等于$m$。$(n,m,a[i] \in [1,5000])$

Solution

思维题,可以发现答案就是大于等于 $m$ 的个数减去小于 $m$ 的个数。

Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n, m, x, s1 = 0, s2 = 0;
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> x;
if (x >= m)
s1++;
else
s2++;
}
cout << max(0, s1 - s1);
return 0;
}
作者

Benboby

发布于

2020-10-02

更新于

2021-01-28

许可协议

Your browser is out-of-date!

Update your browser to view this website correctly.&npsb;Update my browser now

×