Sum
InterviewTime limit1sMemory limit1024 MB
Count the pairs of distinct elements in a sorted array of N distinct integers that add up to S.
- Level
Easy3 of 10
- Topics
- Two pointers, Array
- Solved
- No attempts yet
Problem
Consider an -element strictly increasing integer sequence and an integer .
Write a program to count the number of pairs of elements of whose sum is .
Input
The first line contains and , the length of the sequence and the required sum (, ). The following lines each contain one element (). The elements are distinct and sorted in increasing order.
Output
The only line of output contains the number of pairs of two distinct elements of the sequence whose sum is .