Costume Party
Time limit1sMemory limit128 MB
Count pairs of cows whose lengths sum to at most S.
- Level
Easy3 of 10
- Topics
- Sorting, Two pointers, Array
- Solved
- No attempts yet
Problem
It's Halloween! Farmer John is taking his cows to a costume party, but unfortunately he only has one costume. The costume fits exactly two cows and has length (). Farmer John has cows (), numbered through ; cow has length (). Two cows fit into the costume together if the sum of their lengths is at most . Determine how many pairs of two distinct cows fit into the costume.
Input
- Line 1: Two space-separated integers and
- Lines 2 to : Line contains a single integer
Output
- A single integer: the number of pairs of two distinct cows whose lengths sum to at most . The order of the two cows does not matter.
Hint
In the sample, the costume length is and the cow lengths are . The four valid pairs are the cows of length and ; and ; and ; and and .