题面链接
https://ac.nowcoder.com/acm/contest/23106/F
题面这个题可以想的很简答也可以想的很复杂,我的想法就是排序完后,每次找到中间位置,看是否大于等于m,如果是的话,我们就更新一下ans
的值,然后一直找到不满足或者全部分解完,每找到一个就将末尾的元素删除,这样就能算出中位数了详情请看代码
#include
using namespace std;
//----------------�Զ��岿��----------------
#define ll long long
#define mod 1000000007
#define endl "\n"
#define PII pair
int dx[4]={0,-1,0,1},dy[4]={-1,0,1,0};
ll ksm(ll a,ll b) {
ll ans = 1;
for(;b;b>>=1LL) {
if(b & 1) ans = ans * a % mod;
a = a * a % mod;
}
return ans;
}
ll lowbit(ll x){return -x & x;}
const int N = 2e6+10;
//----------------�Զ��岿��----------------
int n,m,q,a[N];
int main()
{
int t;
scanf("%d",&t);
while(t--){
scanf("%d%d",&n,&m);
for(int i = 1;i = 1){
if(a[(1+r)>>1] >= m) r--,ans++;
else break;
}
if(ans == 0) puts("-1");
else printf("%d\n",ans);
}
return 0;
}