Cod sursa(job #587561)

Utilizator antonioteoZait Teodor Antonio antonioteo Data 5 mai 2011 09:27:14
Problema Avioane Scor 50
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.49 kb
# include <fstream>
# include <algorithm>
# define MAXN 100000
using namespace std;
ifstream f ("avioane.in"); 
ofstream g ("avioane.out");
int N, l, smax;
int V[ MAXN ];

int main(){
	f >> N;  for ( int i = 1; i <= N; ++i ) f >> V[ i ];
	sort ( V + 1, V + N + 1 );
	for (register int i = 1; i <  N; ++i ){
		for ( register int j = i + 1; j <= N; ++j ){
			l = V[ i ] * ( j - i ) + V[ j ] * ( N - j + 1 );
			if ( l > smax ) smax = l;
		}	
	}
	g << smax << '\n';
	return 0;
}