I have to reduce execution time in this code. In this problem the value of n may go upto 10^8 . And hence i think nested loops are not that good because it is very laggy for large data's . So I was wondering if I use a function instead of the inner loop . Will this idea work for reduction of execution time?? or it will be the same case even if i use funtions??
#include <stdio.h>
long long a[500001]={0};
int main()
{
long long n,i,j,flag,sum=0,temp,count=0;
scanf("%lld",&n);
for(i=0;i<n;i++)
scanf("%lld",&a[i]);
for(i=0;i<n;i++){
for(j=0;j<n;j++)
if(a[j]>=a[i])
count++;
flag=a[i]*(count);
if(flag>sum)
sum=flag;
count=0;
}
printf("%lld",sum);
return 0;
}