AD1

Saturday, 23 September 2017

Count pairs with given sum

Problem :

Solution :

#include <iostream>
using namespace std;
int main()
{
int T;
cin>>T;
for(int i=0;i<T;i++)
{
int N,K;
int counter=0;
cin>>N>>K;
int array[N];
for(int j=0;j<N;j++)
{
cin>>array[j];
}
for(int m=0;m<N-1;m++)
{
for(int l=m+1;l<N;l++)
{
if(array[m]+array[l]==K)
{
counter++;
}
}
}
cout<<counter<<endl;
}
return 0;
}
view raw pairs.cpp hosted with ❤ by GitHub

No comments:

Post a Comment