cswork / OAOpen practice workspace

VisaOA #11

Count Triplets with Sum ≤ t

Estimated MediumJudge-ready

Topics (AI-labelled)Two PointersIn-place Arrays

Given an array of distinct positive integers, count triplets with i<j<k whose sum is ≤t.

Input

n,t (3≤n≤2500), followed by n distinct positive integers (≤10⁹). These limits are site-added.

Output

Output the number of triplets.

Example 1

Input:

5 8
1 2 3 4 5

Output:

4

Example 2

Input:

3 6
1 2 3

Output:

1

Example 3

Input:

4 10
2 5 8 11

Output:

0

Editorial

Loading solution…