why is this exceeding the time limit?
#include
#include
using namespace std;
int main()
{
int n;
cin>>n;
int arr[n];
for (int i=0; i<n; i++)
{
cin>> arr[i];
}
sort (arr, arr+n);
int key;
cin>>key;
for (int x=0; x<n; x++)
{
int left= arr[x+1];
int right= arr[n-1];
while (left<right)
{
int sum= arr [x] + left +right;
if (sum==key)
{
cout << arr [x] << ", "<< left << " and " << right << endl;
}
else if (sum<key)
left++;
else if (sum>key)
right--;
}
}
return 0;
}