Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
The abstract problem asks to count the number of disjoint pairs with a given sum k.
For each possible value x, it can be paired up with k - x.
The number of such pairs equals to min(count(x), count(k-x)), unless that x = k / 2, where the number of such pairs will be floor(count(x) / 2).