AtCoder Grand Contest 012 A
A - AtCoder Group Contest
Time limit : 2sec / Memory limit : 256MB
Score : 300 points
Problem Statement
There are 3N participants in AtCoder Group Contest. The strength of the i-th participant is represented by an integer ai. They will form N teams, each consisting of three participants. No participant may belong to multiple teams.
The strength of a team is defined as the second largest strength among its members. For example, a team of participants of strength 1, 5, 2 has a strength 2, and a team of three participants of strength 3, 2, 3 has a strength 3.
Find the maximum possible sum of the strengths of N teams.
Constraints
- 1≤N≤105
- 1≤ai≤109
- ai are integers.
Input
Input is given from Standard Input in the following format:
N a1 a2 … a3N
Output
Print the answer.
Sample Input 1
2 5 2 8 5 1 5
Sample Output 1
10
The following is one formation of teams that maximizes the sum of the strengths of teams:
- Team 1: consists of the first, fourth and fifth participants.
- Team 2: consists of the second, third and sixth participants.
Sample Input 2
10 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000
Sample Output 2
10000000000
The sum of the strengths can be quite large.
题意:给3*N个数,3个一组,我们取每个组第二大的数出来相加,问最大能够是多少~
解法:排序,取2,4,6,8..就行
#include<bits/stdc++.h> using namespace std; #define ll long long ll sum=0; ll a[3*123456]; bool cmd(ll x,ll y) { return x>y; } int main() { int n; cin>>n; for(int i=1;i<=3*n;i++) { cin>>a[i]; } int i=2; sort(a+1,a+1+3*n,cmd); while((n)--) { sum+=a[i]; //cout<<a[i]<<endl; i+=2; } cout<<sum<<endl; return 0; }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
· 三行代码完成国际化适配,妙~啊~