Cod sursa(job #1173913)
Utilizator | Data | 21 aprilie 2014 02:33:34 | |
---|---|---|---|
Problema | Avioane | Scor | 30 |
Compilator | cpp | Status | done |
Runda | Teme Pregatire ACM Unibuc 2013 Semestrul 2 | Marime | 0.57 kb |
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long int lld;
const int NMAX = 100000+5;
int N,V[NMAX];
lld sol;
int main()
{
int i,j;
lld s;
freopen("avioane.in","r",stdin);
freopen("avioane.out","w",stdout);
scanf("%d",&N);
for(i=1; i<=N; i++)
scanf("%d",&V[i]);
sort(V+1,V+N+1);
for(i=1; i<=N; i++)
for(j=i; j<=N; j++)
{
s=(j-i+1LL)*V[i]+(N-j*1LL)*V[j+1];
if(s>sol) sol=s;
}
printf("%lld\n",sol);
return 0;
}