AtCoder Beginner Contest 151
AtCoder Beginner Contest 151
https://atcoder.jp/contests/abc151
这一套质量一般
E - Max-Min Sums
组合数学
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 1e5 + 5, mod = 1e9 + 7;
ll a[N], n, k, sum;
ll fact[N], infact[N];
ll qmi(ll a, ll k, int p){
ll res = 1;
while(k){
if(k & 1)
res = (ll)res * a % p;
a = (ll)a * a % p;
k >>= 1;
}
return res;
}
ll C (int a, int b) {
if (a < b) return 0;
return fact[a] * infact[b] % mod * infact[a - b] % mod;
}
int main () {
fact[0] = infact[0] = 1;
for(int i = 1; i < N; i++){
fact[i] = (ll)fact[i-1] * i % mod;
infact[i] = (ll)infact[i-1] * qmi(i, mod - 2,mod) % mod;
}
cin >> n >> k;
for (int i = 1; i <= n; i++) cin >> a[i];
sort (a + 1, a + n + 1);
for (int i = 1; i <= n; i++) (sum += a[i] * (C (i - 1, k - 1) - C (n - i, k - 1) + mod) % mod) %= mod;
cout << (sum + mod) % mod;
}
F - Enclose All
最小圆覆盖
不想写计算几何。