#include<iostream> #include<algorithm> #include<numeric> using namespace std; int helper(int a[],int n, int t) { sort(a,a+n); int k = 0; int left = 0; int right = n-1; while(left < right) { int sumtwo = a[left] + a[right]; if(sumtwo == t) {left++;right--;k++;} else if(sumtwo>t) right--; else left++; } return k; } int main() { int a[] = {1,2,3,4,5}; cout<<helper(a,5,6); }