Created
January 14, 2012 16:12
[POJ] 2231 - Moo Volume - http://kuoe0.ch/379/poj-2231-moo-volume/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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