Time limit exceeded

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;

}

here in this if statement ,update atleast on of the pointer(left or right)

otherwise which will stuck in infinite loop

updated both the pointers. still the same error

check now->

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.