```
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
long long int maxP=-1;
vector<int> v(n);
for(long long int i=0;i<n;i++)
cin>>v[i];
sort(v.begin(),v.end());
for(long long int i=0;i<n;i++){
long long int c=(n-i)*v[i];
maxP=max(maxP,c);
}
cout<<maxP;
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
long long int maxP=-1;
vector<int> v(n);
for(int i=0;i<n;i++)
cin>>v[i];
sort(v.begin(),v.end());
for(int i=0;i<n;i++){
long long int c=(n-i)*v[i];
maxP=max(maxP,c);
}
cout<<maxP;
return 0;
}
```

QUESTION LINK

Why the first code works and not the second(despite the fact that maximum value of N is 5*10^5 ) ?