Skip to main content
Back to problems
Codeforces
Easy
Math
Greedy
Arrays
Choosing Teams

Count how many 3-person teams can be formed when each team must have a total skill level below a limit.

Acceptance 0%
Problem Statement

Choosing Teams

You are given the skills of nn participants and a threshold kk.

A team can be formed by choosing exactly 3 participants. A team is considered valid only if the sum of their skills is strictly less than kk.

Your task is to determine how many valid teams can be formed from the given participants.

Since the answer may be large only in more general settings, use a standard integer type suitable for counting teams.

Key idea

For every possible group of three participants, check whether the sum of their skills is below the limit, and count it if it is.

Input Format

  • The first line contains two integers nn and kk.
  • The second line contains nn integers representing the skills of the participants.

Output Format

Print a single integer — the number of valid teams of size 3 whose skill sum is strictly less than kk.

Constraints

  • 1n1001 \le n \le 100
  • 1skilli1001 \le skill_i \le 100
  • 1k3001 \le k \le 300

These bounds are consistent with a brute-force or lightly optimized counting approach.

Examples
Sample cases returned by the problem API.

Example 1

Input

3 6
1 2 3

Output

1

Explanation

There is only one team of 3 participants, and their sum is 1 + 2 + 3 = 6, which is not strictly less than 6. So the answer is 0.

Note: if the threshold were 7, the answer would be 1. This example illustrates the strict comparison requirement.

Example 2

Input

4 6
1 1 1 1

Output

4

Explanation

Every choice of 3 participants has sum 3, which is strictly less than 6. There are C(4,3) = 4 such teams.

Premium problem context

Unlock deeper context for this problem

Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.