首页 > 代码库 > 贪心/poj 2231 Moo Volume

贪心/poj 2231 Moo Volume

#include<cstdio>#include<cstring>#include<algorithm>using namespace std;long long a[10010];int main(){    int n;    scanf("%d",&n);    for (int i=1;i<=n;i++) scanf("%lld",&a[i]);    sort(a+1,a+n+1);    long long ans=0;    for (int i=1;i<=n;i++) ans+=a[i]*(2*i-n-1);    printf("%lld\n",ans*2);    return 0;}

 

贪心/poj 2231 Moo Volume