题目描述
Team Contest
You are a staff member of a university.
Your university is registering several teams to participate in a programming contest.
The programming contest is participated by teams of three programmers.
In your university, there are $N$ eligible programmers, numbered from $0$ to $N - 1$.
For each $i$ such that $0 \le i \le N - 1$, programmer $i$ has a skill level of $L[i]$.
The skill level of a team consisting of programmer $i$, $j$, and $k$ is $\min(L[i], L[j], L[k]) + \max(L[i], L[j], L[k])$.
You want to only register teams with a skill level of strictly more than $K$.
Each programmer may only be assigned to at most one registered team.
You want to know the maximum number of teams you can register.
Implementation Details
You should implement the following procedure:
int maximum_teams(int N, int K, int[] L);
- $N$: the number of programmers.
- $K$: the skill level limit of the registered teams.
- $L$: an array of length $N$ describing the skill level of the programmers.
- This procedure should return the maximum number of teams you can register.
- This procedure is called exactly once.
Examples
Example 1
Consider the following call:
maximum_teams(8, 6, [5, 4, 6, 2, 3, 2, 1, 1])
You can register a team with programmer $0$, $3$, and $5$ (with skill levels $5$, $2$, $2$ respectively) and a team with programmer $1$, $2$, and $4$ (with skill levels $4$, $6$, $3$ respectively).
There is no way to register more than two teams.
Therefore, the procedure maximum_teams should return $2$.
Constraints
- $1 \le N \le 100\,000$
- $1 \le K \le 10^8$
- $1 \le L[i] \le 10^8$ (for each $i$ such that $0 \le i \le N - 1$)
Sample Grader
The sample grader reads the input in the following format:
- line $1$: $N \; K$
- line $2$: $L[0] \; L[1] \; \ldots \; L[N - 1]$
The sample grader prints your answer in the following format:
- line $1$: the return value of
maximum_teams
You are an expert competitive programmer. You will be given a problem statement, test case constraints and example test inputs and outputs. Please reason step by step about the solution, then provide a complete implementation in C++17. You should correctly implement the routine(s) described in Implementation Details, without reading or writing anything directly from stdin or to stdout, as input and output are passed through the implemented routines. Assume your code will be run on the OFFICIAL grader, and do not add a main, a sample grader, or any other functionality unless it has been explicitly requested.
Put your final solution within a single code block: cpp
<your code here>
Problem statement (Team Contest)
You are a staff member of a university.
Your university is registering several teams to participate in a programming contest.
The programming contest is participated by teams of three programmers.
In your university, there are $N$ eligible programmers, numbered from $0$ to $N - 1$.
For each $i$ such that $0 \le i \le N - 1$, programmer $i$ has a skill level of $L[i]$.
The skill level of a team consisting of programmer $i$, $j$, and $k$ is $\min(L[i], L[j], L[k]) + \max(L[i], L[j], L[k])$.
You want to only register teams with a skill level of strictly more than $K$.
Each programmer may only be assigned to at most one registered team.
You want to know the maximum number of teams you can register.
Implementation Details
You should implement the following procedure:
int maximum_teams(int N, int K, int[] L);
- $N$: the number of programmers.
- $K$: the skill level limit of the registered teams.
- $L$: an array of length $N$ describing the skill level of the programmers.
- This procedure should return the maximum number of teams you can register.
- This procedure is called exactly once.
Examples
Example 1
Consider the following call:
maximum_teams(8, 6, [5, 4, 6, 2, 3, 2, 1, 1])
You can register a team with programmer $0$, $3$, and $5$ (with skill levels $5$, $2$, $2$ respectively) and a team with programmer $1$, $2$, and $4$ (with skill levels $4$, $6$, $3$ respectively).
There is no way to register more than two teams.
Therefore, the procedure maximum_teams should return $2$.
Constraints
- $1 \le N \le 100\,000$
- $1 \le K \le 10^8$
- $1 \le L[i] \le 10^8$ (for each $i$ such that $0 \le i \le N - 1$)
Sample Grader
The sample grader reads the input in the following format:
- line $1$: $N \; K$
- line $2$: $L[0] \; L[1] \; \ldots \; L[N - 1]$
The sample grader prints your answer in the following format:
- line $1$: the return value of
maximum_teams
Execution limits
Your solution will have 1.0 second(s) execution time and 2048 MB memory limit to solve each test case.
Starting code
Here's your starting code with some skeleton/placeholder functionality:
#include "team.h"
#include <vector>
int maximum_teams(int N, int K, std::vector<int> L) {
return 0;
}
参考函数签名
#include "team.h"
#include <vector>
int maximum_teams(int N, int K, std::vector<int> L) {
return 0;
}
请在 submission.cpp 中实现该函数(可 #include "problem.h" 获取题目提供的声明)。判题时你的代码会与题目提供的 grader 一起编译链接。
输入格式
本题是函数题,由 grader 调用你实现的函数。
输出格式
由 grader 打印判定结果,无需自行读写 stdin/stdout。
样例输入
样例输出
提示
include "team.h"
include <vector>
int maximum_teams(int N, int K, std::vector<int> L) {
return 0;
}