跳到正文

题解

题解 AT2361【 [AGC012A] AtCoder Group Contest】

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

文章信息

发布
2021年2月28日
收录
2026年10月12日
更新
2026年11月21日
篇幅
约 1 分钟
获赞
3

版本

  1. v1当前

前言

cnblogs

Solution\sf{Solution}

显然要用到贪心的思想。

既然最终的结果只与每组强度第二大选手有关,那就考虑如何让他的值尽可能大。

其实,从小到大排个序就能解决,越靠后的值越大,使得每组强度第二大选手的值最大。

最后 O(n)O(n) 扫一遍,更新 ansans 的值。

Code\sf{Code}

代码短得可怜。

C++
#include<iostream>
#include<algorithm>
using namespace std;
#define ll long long
ll n,a[300005],ans;
inline bool cmp(int x,int y){return x<y;}
signed main()
{
	ios::sync_with_stdio(false);
	cin>>n;
	int mn=n*3;
	for(int i=1;i<=mn;++i)
		cin>>a[i];
	sort(a+1,a+mn+1,cmp);//排序
	for(int i=mn-1;i>=n+1;i-=2)
		ans+=a[i];//逐一统计每组的值,更新ans
	cout<<ans<<"\n";//atcoder 换行
	return 0;
}