codeforces round #415 div2

由于下午硬钢树套树和大力颓废就没补完

C:我傻逼比赛时没做出来。。。就是排个序然后算贡献

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N  = 300010, mod = 1000000007;
int n;
ll ans, t = 1;
ll a[N], bin[N];
bool cp(int i, int j) { return i < j; }
int main()
{
    scanf("%d", &n);
    bin[0] = 1;
    for(int i = 1; i <= n; ++i) 
    {
        scanf("%lld", &a[i]);
        t = t * 2ll % mod;
        bin[i] = (bin[i - 1] + t) % mod;
    }
    sort(a + 1, a + n + 1, cp);
    for(int i = 2; i <= n; ++i) 
        ans = (ans + a[i] % mod * bin[i - 2] % mod) % mod;
    for(int i = n - 1; i; --i) 
        ans = ((ans - a[i] % mod * bin[n - i - 1] % mod) % mod + mod) % mod;
    printf("%lld
", ans);         
    return 0;
}
View Code
原文地址:https://www.cnblogs.com/19992147orz/p/6918858.html