Getting error /bin/run.sh: line 4: 18 Segmentation fault (core dumped) ./exe
code:-
#include
#include <bits/stdc++.h>
#include
using namespace std;
int main()
{
int t, n, m;
cin >> t;
while(t >0)
{
cin >> n;
int a[n]={0};
for(int i=0; i<=n-1; i++)
{
cin >> a[i];
}
sort(a,a+n);
cin >> m;
int difference =INT_MAX;
for(int j=0; j<=n-2; j++)
{
for(int k=j+1; j<=n-1; k++)
{
if(a[j] + a[k] == m)
{
if(a[k] - a[j] < difference)
{
cout << "Deepak should buy roses whose prices are "<< a[j] << " and " << a[k] << “.”<< endl;
difference = a[k] - a[j];
}
}
}
}
t–;
cout << endl;
}
return 0;
}