Cod sursa(job #3202469)

Utilizator hhhhhhhAndrei Boaca hhhhhhh Data 11 februarie 2024 16:50:28
Problema Avioane Scor 50
Compilator cpp-64 Status done
Runda Concurs for fun Marime 0.52 kb
#include <bits/stdc++.h>

using namespace std;
ifstream fin("avioane.in");
ofstream fout("avioane.out");
typedef long long ll;
ll n,v[100005];
int main()
{
    ios_base::sync_with_stdio(false);
    fin.tie(0);
    fin>>n;
    for(int i=1;i<=n;i++)
        fin>>v[i];
    sort(v+1,v+n+1);
    reverse(v+1,v+n+1);
    ll ans=0;
    for(int i=1;i<=n;i++)
        for(int j=i+1;j<=n;j++)
        {
            ll val=1LL*i*v[i]+1LL*(j-i)*v[j];
            ans=max(ans,val);
        }
    fout<<ans;
    return 0;
}