#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 ) ?
@anon49701446 Actually the whole coding was done in parameter ‘t’, while writing here I changed it to ‘n’. The ‘t’ with vector remained unnoticed. So, consider that I do not have any compilation error w.r.t. any parameter not defined. Help me why I am getting answer in first code, while not in second code.
Thanks