# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
9533 | kkjjkk | Uniting (kriii2_U) | C++98 | 0 ms | 2456 KiB |
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 <algorithm>
#include <iostream>
#include <cstdio>
using namespace std;
long long h[100005];
int main()
{
int n;
scanf("%d", &n);
for(int i = 0; i < n; i++) scanf("%lld", &h[i]);
if(n == 1) printf("0\n");
else if(n == 2) { printf("%d\n", h[0] * h[1]); }
else {
sort(h, h + n);
long long a = h[0] + h[1];
long long b = h[0] * h[1];
long long c, d;
for(int i = 2; i < n; i++) {
c = a + h[i];
d = a * h[i]; //d %= ;
a = c;
b += d; b %= 1000000007;
}
printf("%lld\n", b);
}
printf("-1");
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |