bzoj1679

来源:互联网 发布:淘宝美工速成教程 编辑:程序博客网 时间:2024/05/17 06:26

刷水题提高自信

#include<bits/stdc++.h>using namespace std;#define FOR(i,s,t) for(int i=(s);i<=(t);i++)inline int read(void){    int x = 0, c, f = 1;    do{c=getchar();if(c=='-')f=-1;}while(c<'0'||c>'9');    do{x=x*10+c-'0';c=getchar();}while(c>='0'&&c<='9');    return x * f;}typedef long long LL;const int N = 11000;int a[N];int n;int main() {    n = read();    for (int i = 1; i <= n; i++) a[i] = read();    sort(a + 1, a + n + 1);    LL sum = a[1], tot = 0;    for (int i = 2; i <= n; i++) {        tot += (LL) a[i] * (i - 1) - sum;        sum += a[i];    }    cout << 2 * tot << endl;}
原创粉丝点击