Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
[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
You can’t perform that action at this time.