跳到正文

个人记录

Basketball 题解

Silence_in_Sea约 1 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2026年4月26日
篇幅
约 1 分钟

版本

  1. v1当前

官方题解。

很容易得出一个结论,我们可以发现,前面选的中位数大一些并不能使后面选的小一些,因为中位数与比它小的数的大小无关,但和个数有关。

先排序。

令 k=nmk = \frac{n}{m}。

考虑一个贪心的思路,我们对于每个选中的中位数,只需要选择 k−12\frac{k-1}{2} 个比其小的即可。

所以正解就是在前 m×k+12m \times \frac{k+1}{2} 个人中,每 k+12\frac{k+1}{2} 个选择其中最大的数加和。

std:

C++
#include <bits/stdc++.h>
using namespace std;

int a[5000005];
int main(){
	ios::sync_with_stdio(false);
	int n,m;
	cin>>n>>m;
	int s=(n/m+1)/2;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	sort(a+1,a+1+n);
	long long ans=0;
	for(int i=1,j=s;i<=m;i++,j+=s){
		ans+=a[j];
	}
	cout<<ans<<endl;
	return 0;
}
原文