This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<stdio.h>
#include<stdlib.h>
#include<algorithm>
#include<vector>
using namespace std;
#define MOD 1000000007
int n,r[100005];
long long int a[100005];
long long int v[100005],s[100005];
int main()
{
int i,j,k,t=0;
scanf("%d",&n);
for(i=0;i<n;i++)scanf("%lld",&a[i]);
sort(&a[0],&a[n]);
s[0]=a[0];
for(i=1;i<n;i++)s[i]=s[i-1]+a[i];
for(i=0;i<n;i++)
{
for(j=i+1;;j++)
{
if(a[j]!=a[i])
{
r[i]=j;
break;
}
}
}
for(j=r[0];j<n-1;j++)
{
k=r[j];
if(k<n)
{
v[j]=(v[j-1]+(s[n-1]-s[k-1])*(long long int)a[j])%MOD;
}
}
for(i=0;i<n-2;i++)
{
t=(t+(v[n-2]-v[r[i]-1])*(long long int)a[i])%MOD;
}
printf("%lld",t);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |