I am trying to solve the maximum pairwise product problem by first sorting the vector and then multiplying the last two elements of the vector.
It works fine for the smaller digits but not for the 10^5 digits.
Can anyone please look it out and help?
this is my function
long long MaxPairwiseProductFast(const vector<int> &number)
{
long long result = 0;
long n = number.size();
result = number.at(n-1) * number.at(n-2);
return result;
}
and this is my main function
int main()
{
int n;
cin>>n;
vector<int>numbers(n);
for(int i = 0; i <n; i++){
cin>>numbers[i];
}
sort(numbers.begin(), numbers.end());
long long result = MaxPairwiseProductFast(numbers);
cout<<result<<"\n";
return 0;
}
it works fine for smaller range, but not for the bigger range even after using long long