include
include
using namespace std;
void targetSum(int*,int,int);
int main()
{
int n,target;
cin>>n>>target;
int arr[n];
for(int i=0;i<n;i++)
{
cin>>arr[i];
}
targetSum(arr,n,target);
return 0;
}
void targetSum(int arr[], int n,int target){
sort(arr,arr+n);
int left = 0;
int right = n - 1;
while (left < right) {
int sum = arr[left] + arr[right];
if (sum > target) {
right–;
} else if (sum < target) {
left++;
} else {
cout<<arr[left] << " and " << arr[right];
left++;
right–;
}
}
}
Output :
TESTCASE # 1 : wrong-answer (Time: 0 s)
TESTCASE # 2 : no-output (Time: 0 s)
TESTCASE # 3 : no-output (Time: 0 s)
TESTCASE # 4 : no-output (Time: 0 s)