Skip to content

Instantly share code, notes, and snippets.

@kuoe0
Created January 14, 2012 16:12
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save kuoe0/1611911 to your computer and use it in GitHub Desktop.
[POJ] 2231 - Moo Volume - http://kuoe0.ch/379/poj-2231-moo-volume/
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
using namespace std;
int pos[ 10010 ];
int main() {
int n;
while ( ~scanf( "%d", &n ) ) {
for ( int i = 0; i < n; ++i )
scanf( "%d", &pos[ i ] );
sort( pos, pos + n );
long long int ret = 0;
for ( int i = 0; i < n - 1; ++i )
ret += ( long long int )( pos[ i + 1 ] - pos[ i ] ) * ( long long int )( n - 1 - i ) * ( i + 1 );
printf( "%lld\n", ret << 1 );
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment