General

# Author Problem Lang Verdict Time Memory Sent Judged
35369123 Contestant:
tun
938E - 22 GNU C++14 Accepted 468 ms 29248 KB 2018-02-16 20:04:12 2018-02-17 16:55:15

→ Source
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using vi = vector<int>;
using db = double;
using pii = pair<int,int>;
#define pb push_back
#define fir first
#define sec second

const int mxn = 1000006;
const ll mod = 1E9L+7;

int a[mxn];
ll sum;

ll inv[mxn];
ll fac[mxn];
ll ifac[mxn];

ll binom(int a, int b) {
return fac[a] * ifac[b] % mod * ifac[a - b] % mod;
}

int main() {

inv[1] = fac[0] = fac[1] = ifac[0] = ifac[1] = 1;
for (int i = 2; i <= 1000000; ++i) {
inv[i] = (ll)mod / i * (mod - inv[mod % i]) % mod;
fac[i] = (ll)fac[i - 1] * i % mod;
ifac[i] = (ll)ifac[i - 1] * inv[i] % mod;
}

int n;
cin >> n;
for (int i = 1; i <= n; ++i)
scanf("%d", &a[i]);

sort(a + 1, a + n + 1);
ll c = 0;
for (int i = 1; i <= n; ++i) if (a[i] < a[n]) {
if (i == 1 || a[i] != a[i - 1])
c = i - 1;
ll s = fac[n - 1 - c] * fac[c] % mod * binom(n, c) % mod;
s %= mod;

//cout << s << endl;
sum += a[i] * s;
sum %= mod;
}

cout << (sum + mod) % mod << endl;

return 0;
}


?
Time: ? ms, memory: ? KB
Verdict: ?
Input
?
Participant's output
?
?
?
?