Submission #9274

#TimeUsernameProblemLanguageResultExecution timeMemory
9274kcm1700Uniting (kriii2_U)C++14
4 / 4
16 ms1476 KiB
#include <cstdio> #include <algorithm> #include <numeric> using namespace std; int n; int dat[100003]; const int mod = 1000000007; int main(){ scanf("%d",&n); for(int i = 0; i < n; i++) scanf("%d",&dat[i]); sort(dat, dat+n); long long sum = accumulate(dat, dat+n, 0ll); long long ans1 = 0; long long ans2 = 1; for(int i = 0; i < n; i++) { sum -= dat[i]; ans1 += dat[i] * sum; if (i >= 1) { ans2 *= (i+1); ans2 %= mod; ans2 *= (i); ans2 %= mod; } } printf("%lld\n%lld\n", ans1,ans2); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...