#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);
}

 

相关文章:

  • 2021-11-09
  • 2021-08-05
  • 2022-01-23
  • 2021-10-09
  • 2022-12-23
  • 2022-01-15
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案